Question

i have some spinners in my activity. The screen is set to lock after 2 minutes. After I unlock the screen, all of my spinners are reset. I think, that the onCreate method is called after unlocking. Is there some way, to set the activity not to recreate after unlocking the screen? The same happens when rotating the screen, but that's not the issue, i can set the layout to be portrait only.

Or maybe is there some setting, like for rotation, to prevent calling the onCreate method again?:

android:configChanges="orientation"

thanks.

Was it helpful?

Solution

http://developer.android.com/reference/android/app/Activity.html

"An activity can frequently go between the resumed and paused states -- for example when the device goes to sleep"

http://developer.android.com/training/basics/activity-lifecycle/pausing.html

You need to manage state using the Activity lifecycle methods, rather than trying to "set the activity not to recreate." Activitys are created/destroyed/recreated all the time, by design (and for the record locking to one orientation is also sort of a band-aid, dealing with state correctly will mean you don't have to do that either).

This question may help, the answer has an example of dealing with instance state: Saving Android Activity state using Save Instance State

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