2

In my app I have a requirement that if the Home button is pressed during the working of app and if the user starts the app from the icon from home screen it must resume from the last activity.

How do I save the last screen history and resume it from the same screen?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Navdroid
  • 4,453
  • 7
  • 29
  • 47

2 Answers2

6

The AlwaysRetainTaskState might be what you're looking for.

In your AndroidManifest, in the activity tag, just add

android:alwaysRetainTaskState="true"
Sam
  • 7,252
  • 16
  • 46
  • 65
Gyscos
  • 1,772
  • 17
  • 22
  • Dude this is working fine on emulator but not on device!! Is there any issue?? – Navdroid May 18 '12 at 08:04
  • It should work too. If the device somehow lacks memory, the application will be killed anyway and you will lose the stack, but this usually doesn't happen... If you want the app to keep the state even after device reboot, then you'll need to save the state, for example in a SharedPreference, and restore it when needed. – Gyscos May 18 '12 at 10:27
  • If the system needs to kill your activity to free memory, it will call onSaveInstanceState, so you can implement your own task saving/restoring mechanism in that case. – Lawrence D'Oliveiro May 18 '12 at 11:03
2

Check out following posts:

Community
  • 1
  • 1
Bo.
  • 2,547
  • 3
  • 24
  • 36