Dr.jacky
Dr.jacky

Reputation: 3547

Does activity destroy when go to next activity?

I have 2 activity A and B.when go from A to B,does A destroy? If yes,does all variables(static or nonstatic) clear or not?

Or if not destroy?does activity goes to some stack?

Upvotes: 0

Views: 519

Answers (1)

Nermeen
Nermeen

Reputation: 15973

it is not destroyed, it will be moved to the stack.. check http://developer.android.com/training/basics/activity-lifecycle/index.html

enter image description here
as Simon said below:
the variables are not destroyed when your activity goes to the stack. However, once an activity is not the active activity, Android may destroy it without any further callbacks to your code. That is what onPause() and onResume() are there for. You should save and restore anything you need to maintain the state of your activity in those methods..

For static vars (If the process is killed then all static variables will be reinitialized to their default values). check Public static variables and Android activity life cycle management

Upvotes: 3

Related Questions