Reputation: 9115
The scenario is like this: I have an activity that starts a thread (through AsyncTask). I get the state correctly saved and restored when changing screen orientation (with onSaveInstanceState and onRestoreInstanceState), the thread is stopped in onStop(). But if I "minimize" (or change app) I get my state saved but NOT restored. What can I do?
-- Edit: Solved Thank you guys, I had found many similar answers but the problems were kinda more elaborated, I thought that a simple question could lead to another solutions but I guess I'm stuck with those two options. onRestoreInstanceState and SharedPreferences. Thanks!
Upvotes: 0
Views: 268
Reputation: 475
Bro, there are two ways to resolve it. First one is very easy. Use onSaveInstanceState()
and onRestoreInstanceState()
to maintaint your activity. 2nd method is to use SharedPreferences :)
Upvotes: 1
Reputation: 8371
Since the rules for when the state is saved and restored depend on situations that you can't easily predict, I'd recommend using a different approach. Using shared preferences is probably the easiest. Here's a link to the storage options reference page that shows how to do that.
Upvotes: 0