tags:

views:

17

answers:

1

I was reading on how Activities communicate and how the calls stack up on top of each other. But at any instant when the OS(or dalvik) is low on resources, it can choose to kill Paused or Stopped Activities. In this scenario, how do we restore previous state of the activity(in which it was before getting killed) when we reach the same activity on our way back.

Does stack store the state as well as references to the Activity? Aren't their chances of achieving a different state when we re-constuct activity (onCreate)?

+2  A: 

In this scenario, how do we restore previous state of the activity(in which it was before getting killed) when we reach the same activity on our way back.

Override onSaveInstanceState() and populate the supplied Bundle with what you need. If you chain to the superclass, Android will populate the Bundle with obvious user-modifiable widget contents (e.g., the text entered into an EditText).

You then get that Bundle back in onCreate() and onRestoreInstanceState().

CommonsWare