Addev
Addev

Reputation: 32233

Activity Lifecycle and the stack of activities

I have an activity with the following screen scheme:

             |------> Activity1
MainActivity |------> Activity2

The application navigation only use startActivity() calls and the standard "back button" function.

Considering an Activity as created when its in between the onCreate and the onDestroy methods.

May I assume that when the activity1 or 2 is created then the MainActivity is created too?

Upvotes: 0

Views: 57

Answers (2)

iTech
iTech

Reputation: 18440

There is no guarantee that the MainActivity will still be alive when you have Activity1/2 in the foreground. Definitely it will be created when the app starts since it is the only way to reach to Activity1/2.

Once the MainActivity is covered by another activity it will be in Stop state and can be killed by the system when resources is needed.

You can have some control over this behavior by specifying android:noHistory="true/false" in your activity definition, which by default set to false

Upvotes: 1

Phil
Phil

Reputation: 36289

Yes, when Activity1 or Activity2 is created, then by your definition MainActivity has also been created. So, if you are trying to access variables or methods from within MainActivity, then will be there.

Upvotes: 0

Related Questions