How DialogFragment Affects the Life Cycle of Challenging Activities

If I started DialogFragment from an action, what happens when I close DialogFragment? Is activity in the β€œResult” state? Or a call like any regular Java call, so the next line is never executed until the dialog box closes?

Suppose the method to run my fragment

private void launchFragment(){ ConfirmationDialog confirm = new ConfirmationDialog(); confirm.show(getSupportFragmentManager(), "confirm"); doMoreStuff(); } 

So my question is twofold:

  • When doMoreStuff() is called? Before or after closing a fragment to return to parental activity?
  • After I close the fragment to return to the parent activity, does the parent activity perform onResume: so if I have a check for some field changed by the fragment, I can work in onResume based on the state of this field:

As in the following example:

 @Override public void onResume() { super.onResume(); if(dialogFragmentChangedThis){ workSomeMore(); } } 

The fragment starts with

 setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

so that it is in full screen mode.

+6
source share
1 answer

When doMoreStuff () is called? Before or after closing a fragment to return to parental activity?

DialogFragment show() method simply performs a FragmentTransaction , which will be executed asynchronously, so any subsequent method will be executed immediately.

After I close the fragment to return to the parent activity, does the parent activity execute onResume

No, this is not so, since your Activity is in the foreground all the time, since there are no other Activities .

Typically, you use Callbacks listeners with DialogFragment , as is done with simple Fragment s, by implementing callbacks in the Activity and by calling the Activity method through this interface when you want to pass the result of the action that happened in DialogFragment .

+5
source

All Articles