0

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!

arielnmz
  • 8,354
  • 9
  • 38
  • 66

2 Answers2

1

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

Attiq ur Rehman
  • 475
  • 1
  • 6
  • 21
0

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.

scottt
  • 8,301
  • 1
  • 31
  • 41