Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status of first activity in android while second activity is active

using intent, when we are moving from first activity to second activity, what should be status of first activity.. means its onPause() or onStop() ?

like image 831
Axay Prajapati Avatar asked Dec 09 '25 05:12

Axay Prajapati


2 Answers

It can be either in onPause() or onStop() depending on the screen width and height occupied by the next activity.

If next activity occupies entire screen then previous activity would be in onStop(), as the previous activity won't be visible. the sequence will be onPause() and then onStop().

However if next activity does not occupy entire screen (eg. activity with Dialog theme ) and previous activity is visible behind new activity, in that case previous activity will be in onPause().

Activity Lifecycle

Foreground lifetime of an activity

The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all other activities and interacting with the user. An activity can frequently go between the resumed and paused states -- for example when the device goes to sleep, when an activity result is delivered, when a new intent is delivered -- so the code in these methods should be fairly lightweight

Visible lifetime of an activity

The visible lifetime of an activity happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen, though it may not be in the foreground and interacting with the user. Between these two methods you can maintain resources that are needed to show the activity to the user. For example, you can register a BroadcastReceiver in onStart() to monitor for changes that impact your UI, and unregister it in onStop() when the user no longer sees what you are displaying. The onStart() and onStop() methods can be called multiple times, as the activity becomes visible and hidden to the user.

Entire lifetime of an activity

The entire lifetime of an activity happens between the first call to onCreate(Bundle) through to a single final call to onDestroy(). An activity will do all setup of "global" state in onCreate(), and release all remaining resources in onDestroy(). For example, if it has a thread running in the background to download data from the network, it may create that thread in onCreate() and then stop the thread in onDestroy().

like image 75
Ritesh Gune Avatar answered Dec 11 '25 21:12

Ritesh Gune


First your Activity go in onPause() mode, if your Activity no longer visible then it will be go in onStop() mode.

Check this for more information about Activity LifeCycle

enter image description here

like image 31
Niranj Patel Avatar answered Dec 11 '25 22:12

Niranj Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!