Answer the question
In order to leave comments, you need to log in
Where does the fragment go?
I have a regular DialogFragment to show a ProgressBar
public class LoadingDialogFragment extends DialogFragment {
public static final String TAG = "LoadingDialogFragment";
public static LoadingDialogFragment newInstance() {
return new LoadingDialogFragment();
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loading_indicator);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
return dialog;
}
}
protected void showLoadingDialogFragment() {
LoadingDialogFragment dialog = LoadingDialogFragment.newInstance();
dialog.setCancelable(false);
dialog.show(getSupportFragmentManager(), LoadingDialogFragment.TAG);
}
protected void hideLoadingDialogFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(LoadingDialogFragment.TAG); // здесь null
if (fragment instanceof LoadingDialogFragment) {
((DialogFragment) fragment).dismiss();
}
}
getSupportFragmentManager().findFragmentByTag(LoadingDialogFragment.TAG);
returns null (I indicated this place in the code), despite the fact that this very dialog is displayed on the screen. How can you catch the error? what am I doing wrong, where does the fragment from the FragmentManager disappear to?
Answer the question
In order to leave comments, you need to log in
Of course, "but after the end of the data loading" is a very weak clue and there are a lot of options for the turn of events.
I would venture to guess that the FragmentManager that returns null is no longer the instance that existed when the dialog was launched. This happens, for example, as a result of changing the orientation of the device.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question