When i press home button on my app, it will take me to the desktop menu
. And when i open it again the last state is not maintained. Last state of the Activity is not saved
. Whereas it normally should save the last state on Home Press. Why is it so?

- 33,936
- 20
- 234
- 300

- 1
-
You mean you want to exit app on pressing Home? So next time you want the app to be started again? – MysticMagicϡ Sep 02 '14 at 07:29
-
please post some more useful information. – suitianshi Sep 02 '14 at 07:30
-
1its very difficult to understand your question. – jaimin Sep 02 '14 at 07:35
-
I mean I am pressing the home key, and then click the program's desktop icon again ,it should come back before UI,but it not. – Gray Sep 02 '14 at 07:39
-
Android kill your Activity whenever it needs space/memory. you may have less memory or running multiple apps at one time – Zar E Ahmer Sep 02 '14 at 07:46
-
Don't press desktop icon again . Hold home button for 2 sec ..Your running app will shown to you. then open it and you are good to go.. – Zar E Ahmer Sep 02 '14 at 07:47
-
What kind of thing do you want to save and make visible when you re-open your app? Is it text data or something else? – Confuse Sep 02 '14 at 07:47
-
can u please elaborate your question @Gray not clear – Spry Techies Sep 02 '14 at 07:53
-
Check this Answer it contains code sample: http://stackoverflow.com/a/25400275/1826581 – Mohamed Fadl Allah Sep 02 '14 at 08:04
2 Answers
According to your comment . you are opening another desktop icon while your app is running in background. it means you are opening a new instance. Follow steps.
After pressing home button you move to desktop menu.
Press and hold home button again for two/three seconds . Your app will be shown to you in a small screen at the botton . Select it, it will show you the last state if and only if Android doesn't kill it for memory/space.
And you can also save state of an Activity by setting a variable in Manifest which will always hold that activity in memory and save it state.

- 33,936
- 20
- 234
- 300
Override the onSaveInstanceState(Bundle) in your activity and save the UI state to the supplied Bundle. This function is called when your activity is stopped.
When the application later is restarted use a overridden onRestoreInstanceState(Bundle) to read the saved data and setup the UI to the correct state.
Cheers!

- 8,315
- 3
- 33
- 51