简体   繁体   中英

Android: lifecycle, onRestoreInstanceState not called when Phone turned

I use these functions in an activity class: onSaveInstanceState onRestoreInstanceState onPause onCreate

When the user starts the Activity onCreate gets called, when the user ends, onPause gets called. Thats fine so far.

But when the user rotates the phone, onPause onSaveInstanceState onCreate gets called. I would have expected onRestoreInstanceState before onCreate. Why is this so and how should I handle initialization of ui-data if not there?

I would have expected onRestoreInstanceState before onCreate.

The documentation for onRestoreInstanceState() clearly states:

This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation.

If you wish to initialize your UI with stuff from the Bundle in onCreate() , feel free to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM