0

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?

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91

1 Answers1

3

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

Community
  • 1
  • 1
Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • 3
    @Dr.jacky For completeness, 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. – Simon Nov 07 '12 at 10:41
  • @Simon 1-And how to save something to maintain the state?with Preference?2-about static variables,what's happen? – Dr.jacky Nov 07 '12 at 10:45
  • Yes, you can use shared preferences to save the variables, for static vars (If the process is killed then all static variables will be reinitialized to their default values). – Nermeen Nov 07 '12 at 10:49