开发者

Android - Activity and startActvity

开发者 https://www.devze.com 2023-03-11 19:15 出处:网络
I have 2 activities Activity1 and Activity2. I navigate from Activity1 to Activi开发者_开发知识库ty2 (Call startActivity), and when I click back it starts a brand new Activity1.

I have 2 activities Activity1 and Activity2.

I navigate from Activity1 to Activi开发者_开发知识库ty2 (Call startActivity), and when I click back it starts a brand new Activity1.

Is there a way to keep Activity1 alive so that it keeps its state?


When you do a startActivity() from an activity, Android pauses the current activity and puts it in the background. For that moment, onPause() method of current activity is called.

In addition, if you want to save the current state, you can also override the onSavedInstanceState() method.

Check out some of these references as well as the Android Life Cycle.

http://developer.android.com/reference/android/app/Activity.html http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html


Ofcourse there is a way. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack").

http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号