-3

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?

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
Gray
  • 1

2 Answers2

0

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.

  1. After pressing home button you move to desktop menu.

  2. 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.

  3. 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.

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0

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!

mach
  • 8,315
  • 3
  • 33
  • 51