Question

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!

Was it helpful?

Solution 2

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.

OTHER TIPS

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top