Search code examples
androidandroid-fragmentsandroid-dialogfragmentandroid-lifecycle

Fragment and DialogFragment Lifecycle Relationship


I have Fragment "A" where I have an ImageButton in place. Upon clicking this button a DialogFragment "B" is called to the foreground where Fragment "A" is partially visible in the background. DialogFragment "B" presents the user with a list of choices. Upon clicking a specific choice DialogFragment "B" is dismissed via Dismiss() and Fragment "A" becomes fully visible again.

During this action I need to update the ImageButton on Fragment "A" to represent the user's choice made on DialogFragment "B" (basically a new image for the ImageButton).

Am I correct in thinking the right place to update the ImageButton on Fragment "A" is during OnResume? Does Fragment "A" go into OnPause while FragmentDialog "B" is being shown? Therefore upon returning from DialogFragment "B", Fragment "A" would trigger its OnResume and that's where I should make the update changes to the ImageButton being presented to the user?

I hope my explanation is clear. Any detailed help on where and how I should be updating the ImageButton would be highly appreciated.


Solution

  • Fragment A won't go into onPause so onResume won't get called http://developer.android.com/guide/components/fragments.html

    Resumed
    The fragment is visible in the running activity.

    Paused
    Another activity is in the foreground and has focus, but the activity in which this fragment lives is still visible (the foreground activity is partially transparent or doesn't cover the entire screen).