DialogFragment display code example (just shows progress bar)
public void showProgressDialog(boolean isShow) { if(isShow){ if(!mProgressDialog.isAdded()) { mProgressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } } else { mProgressDialog.dismiss(); } } In an application, a situation may arise when this function is called twice at the same time. For the test, you can simply do so
public void showProgressDialog(boolean isShow) { if(isShow){ if(!mProgressDialog.isAdded()) { mProgressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } } else { mProgressDialog.dismiss(); } if(isShow){ if(!mProgressDialog.isAdded()) { mProgressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } } else { mProgressDialog.dismiss(); } } This code will crash with
Fatal Exception: java.lang.IllegalStateException: Fragment already added: ProgressDialog{fffc31f #2 ProgressDialog} at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1892)... As I understand it, adding a fragment happens asynchronously, and therefore isAdded () returns false.
Actually the question is: can this be avoided without entering additional flags / variables?
executePendingTransactionsafter theshow. - post_zeew