DeveryDay
DeveryDay

Reputation: 161

Dismissing Fragment Dialog onResume

I've run into a pretty interesting problem. I attempt to dismiss a Fragment Dialog from within my Activity's onResume method. That is all fine and well until it calls my Dialog Fragment's onDismiss method, which when I call getActivity returns null. Why is this? I suspect it's lifecycle related but after debugging to understand I am still unsure as to why this is happening.

Upvotes: 0

Views: 1763

Answers (1)

Emmanuel
Emmanuel

Reputation: 13223

Since you are calling super.onDismiss() your code will go through the default implementation of onDismiss() hosted in FragmentDialog. From the docs we see that it calls the dismissInternal() which in turn removes the DialogFragment. By the time the code gets to your implementation of onDismiss() the DialogFragment is probably already removed, hence getActivity() returns null.

Upvotes: 1

Related Questions