Android: maintaining state during the Android life cycle

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

I have an activity that can be "interrupted" by the user, for example. the user opens a menu to call up the settings screen. When the preference screen is called up onSaveInstanceState(Bundle), it is called up and I can save my data. So far it has been good. But when you press the back button, it is onRestoreInstanceState(Bundle savedInstanceState)NOT called.

So how can I save my condition? Should I do this when calling a new action? But how? The only way I can think of is to save the state by passing the state of the new activity, do nothing with the saved data, return it to the first activity and restore the state to onActivitResult. But that would mean that I have to transfer data back and forth in order to restore the state. This does not seem to be a good solution.

+3
source share
3 answers

Probably a bad answer, but are you sure you onRestoreInstanceStateshould be called?

onSaveInstanceState/onCreate /onRestoreInstanceState , , , . , , , onCreate / onRestonreInstanceState. , , - -, , .

Android , onSaveInstanceStae / onRestoreInstanceState , , . , . , onResume , onPause , .

Android Lifecycle Picture

+6

, :

onPause() , , onSaveInstanceState() onRestoreInstanceState() . . , Android onSaveInstanceState() , , , (, BACK). , .

onSaveInstanceState() , , . onPause() .

, onPause() onResume(). .

+4

ListView Pref, Pref ( onCreate ).

StanceState , . , , ListActivity .

ListView -?

+1

Source: https://habr.com/ru/post/1788513/


All Articles