Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android life cycle event on dialog

Can you please explain which activity life cycle method is called when a dialog comes on the application? I'm confused whether its is calling onResume() or onPause() method.

Thanks

like image 865
prg Avatar asked Mar 17 '16 05:03

prg


People also ask

Which activity life cycle method gets called whenever a dialog opens on screen?

onPause(): This method gets called when the UI is partially visible to the user. If a dialog is opened on the activity then the activity goes to pause state and calls onPause() method.

What is the life cycle of Android activity?

Activity-lifecycle concepts To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.

What happens to the activity when we launch the dialog?

However, if a dialog appears from System for a permission or some other app shows a Dialog over the activity it will only call OnPause() since a new activity isn't started and only the foreground focus is shifted from the activity to the Dialog Box.


1 Answers

OnPause() is not called in all types of dialogs.

For Example, when an AlertDialog or DialogFragment is used, it will never call OnPause(), since they are a part of the activity.

However, if a dialog appears from System for a permission or some other app shows a Dialog over the activity it will only call OnPause() since a new activity isn't started and only the foreground focus is shifted from the activity to the Dialog Box.

For Example, when we enable Whatsapp to send a message popup, if the popup comes while your activity is running, it will call OnPause() only.

You should try this on your own for better understanding.

like image 151
Anubhav Mittal Avatar answered Sep 22 '22 17:09

Anubhav Mittal