"loading" screen in activity

0

I would like to know or understand how to load a screen. My app does query in a webservice, and sometimes depending on the connection it takes to bring the information. And the app is all white. To the end user it seems that caught. So I would like to put a loading screen.

HTTP request code

    private static final String BASE_URL = "https://LINK DO MEU Json";
private static Retrofit mRetrofit;
private static ApiNOMEDOPROJETORequestInterceptor mInterceptor;
private static Gson mGson;
private static OkHttpClient mClient;

public static Retrofit getInstance() {
    if (mRetrofit == null) {
        //create Gson
        mGson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create();

        //create interceptor
        mInterceptor = new ApiNOMEDOPROJETORequestInterceptor();


        //create httpClient with interceptor
        mClient = new OkHttpClient.Builder().addInterceptor(mInterceptor).build();

        //create retrofit
        mRetrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(mGson))
                .client(mClient)
                .build();
    }
    return mRetrofit;
}

}

    
asked by anonymous 05.10.2016 / 12:34

1 answer

1

Good morning, Arthur, you probably use the async class to make this connection, try using the code below. When calling the class it shows a Dialog pro user, I hope I have helped.

public abstract class AsyncData extends AsyncTask<String, String, String> {

    protected final Context mContext;
    protected final String mMsqInfo;
    protected ProgressDialog mDialog;

public AsyncData(String msgInfo, Context context) {
    mContext = context;
    mMsqInfo = msgInfo;
}

@Override
protected void onPreExecute() {
    if (mIsShowDialog){
        mDialog = new ProgressDialog(mContext);
        mDialog.setTitle(R.string.app_label_wait);
        mDialog.setMessage(mMsqInfo);
        mDialog.setCancelable(true);
        mDialog.show();
    }
}



@Override
protected String doInBackground(String... params) {
    // seu código...
}

@Override
protected void onPostExecute(String results) {
    super.onPostExecute(results);
    if ((mDialog != null) && ( mDialog.isShowing()) {

        mDialog.dismiss();
        mDialog = null;
    }
}

}

    
05.10.2016 / 14:40