Axay Prajapati
Axay Prajapati

Reputation: 811

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() ?

Upvotes: 3

Views: 867

Answers (4)

lynndragon
lynndragon

Reputation: 370

You should practice and learn more at following sites..

Details and tutorials of Activity lifecycle (great tutorials): http://www.vogella.com/tutorials/AndroidLifeCycle/article.html

http://www.tutorialspoint.com/android/android_acitivities.htm

http://docs.xamarin.com/guides/android/application_fundamentals/activity_lifecycle/

How activity lifecycle use for: Android activity life cycle - what are all these methods for?

Hope you get more knowledge..

Upvotes: 0

Yogesh D
Yogesh D

Reputation: 1681

During normal app use, the foreground activity is sometimes obstructed by other visual components that cause the activity to pause. For example, when a semi-transparent activity opens (such as one in the style of a dialog), the previous activity pauses. As long as the activity is still partially visible but currently not the activity in focus, it remains paused.

However, once the activity is fully-obstructed and not visible, it stops and if it remains in stop for long time or if apps with higher priority needs memory then it is destroyed

And one more point when you move from one ctivity to another first onPause() will get called and as the previous activity is no longer visible or on foreground eventually onStop() will be called.

Where as in case of some transparent dialog box activity is paused but as it is still at foreground and visible onStop will not be called in this case

So ultimately coming to your specific question in your case both onPause() and onStop() methods will be executed in sequence

you can read more logical stuff about activity lifecycle here

Upvotes: 1

Ritesh Gune
Ritesh Gune

Reputation: 16739

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().

Upvotes: 4

Niranj Patel
Niranj Patel

Reputation: 33258

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

Upvotes: 1

Related Questions