Reputation: 11
I've searched SO for this but all I can find is people having the opposite problem - they want their app not to reopen to the previous activity, whereas I'm trying to figure out why my app is starting from the main activity every time I reopen it after the system has killed it for memory.
My problem: I have an activity where the user creates data that eventually gets persisted. When I close the app with unsaved data in this activity, and then go and open other apps so that the system needs to kill my app to free memory, I'm losing my data. I am using onSaveInstanceState/onRestoreInstanceState correctly (the data is not lost when I change orientation or turn on power-saving mode), so I know I'm saving the instance data correctly, the problem is that Android is not opening my app to this activity when I restart, so I never have a chance to restore the instance data I saved.
Any idea why my app would not be opening to the last activity I left it on before the system killed it? Thanks.
Upvotes: 0
Views: 226
Reputation: 1002
After the system kills your app, whatever you stored in onSaveInstanceState is deleted, too.
To save state after your app being killed use Shared Preferences or any other Persistent Storage that fits your needs.
You should save your state in onStop
And check for a saved state in your onCreate
to restore it if there is one
Upvotes: 0