sjain
sjain

Reputation: 23344

Calling previous activity method on dialog dismiss

On click of a certain button in class MainActivity, a dialog is shown of some fragment FragDialog:

FragDialog cf = new FragDialog().newInstace();

cf.show(getSupportFragmentManager(), "dialog");

When a hardware back button is pressed OR when an activity MainActivity is focussed, the dialog is dismissed and I returned to the activity MainActivity.

The methods onResume(), onAttach() of activity MainActivity doesn't get called after dialog dismiss.

The idea is to refresh the activity MainActivity after the dialog dismiss in order to get the changed view according to fields selected in the dialog fragment FragDialog.

As mentioned in the doc DialogFragment,

// DialogFragment.show() will take care of adding the fragment
// in a transaction.  We also want to remove any currently showing
// dialog, so make our own transaction and take care of that here.

But adding remove() seems pointless as it doesn't getting called, even dialog is dismissing without it.

I wondered that if this will get called, then I can start the activity MainActivity again to reflect the changes.

Upvotes: 3

Views: 4333

Answers (1)

Lebedevsd
Lebedevsd

Reputation: 950

while you call dialog you are not loosing contrxt of activity, it is not going in inactive state. All you need just make an event to activity when your dialog is closed, it is quite easy if you cancel it by button. Then you just munnually change your View.

Here is nice article about Dialogs http://developer.android.com/guide/topics/ui/dialogs.html

Upvotes: 1

Related Questions