I'm using Retrofit 2 to make a POST request to my server inside a Fragment, like this:
Call<MyResponse> call = apiService.myPost(params);
call.enqueue(myCallback);
mProgress = ProgressDialog.show(getActivity(), "Working", "Working"", true);
I want to dismiss the ProgressDialog when the request is finished, as you can see here:
class myCallback {
onResponse() {
mProgress.dismiss();
}
onFailture() {
mProgress.dismiss();
}
}
However this approach does not work fine, because the user could rotate or leave the current Activity, leading to this error:
Fatal Exception: java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{1ec6c6d0 V.E..... R.....ID 0,0-513,242} not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
at android.app.Dialog.dismissDialog(Dialog.java:341)
at android.app.Dialog.dismiss(Dialog.java:324)
How can I properly dismiss a Dialog in this situation?
varun singh
Dont allow user to dismiss progressbar until you get the response from server and about device rotation problem set android:configChanges="orientation|screenSize" android:screenOrientation="portrait" in your android manifest.xml file