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!

有帮助吗?

解决方案 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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top