I am facing issue with DialogFragment / getSupportFragmentManager / Android version 4.x
01-10 19:46:48.228: E/AndroidRuntime(9879): java.lang.IllegalStateExc
-
onPostResume()
use post resume method to do your work..
I think you are calling show dialog method in onRestart or onResume, so avoid it and use onPostResume() to show your dialog.
讨论(0)
-
Here is the answer in another thread:
Actions in onActivityResult and "Error Can not perform this action after onSaveInstanceState"
also here:
Refreshing my fragment not working like I thought it should
This is an example solving this problem:
DialogFragment loadingDialog = createDialog();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(loadingDialog, "loading");
transaction.commitAllowingStateLoss();
讨论(0)
-
You could check if the current activity isActive() and only in that case start the fragment transaction of DialogFragment. I had a similar problem and this check solved my case.
讨论(0)
-
fragmentView.post(() -> {
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
YourDialog yourDialog = YourDialog.newInstance();
yourDialog.show(ft, "text_data");
});
The goal of post() method in this case is to wait while onResume() of Activity or Fragment will finished.
It works if you want to show DialogFragment from Fragment., f.e. when you want to show your dialog after a system dialog dismissed.
讨论(0)
- 热议问题