简体   繁体   English

Android:生命周期,手机打开时未调用onRestoreInstanceState

[英]Android: lifecycle, onRestoreInstanceState not called when Phone turned

I use these functions in an activity class: onSaveInstanceState onRestoreInstanceState onPause onCreate 我在活动类中使用以下函数:onSaveInstanceState onRestoreInstanceState onPause onCreate

When the user starts the Activity onCreate gets called, when the user ends, onPause gets called. 当用户启动活动时,将调用onCreate,当用户结束时,将调用onPause。 Thats fine so far. 到目前为止还可以。

But when the user rotates the phone, onPause onSaveInstanceState onCreate gets called. 但是,当用户旋转手机时,会调用onPause onSaveInstanceState onCreate。 I would have expected onRestoreInstanceState before onCreate. 我本来希望onCreate之前有onRestoreInstanceState。 Why is this so and how should I handle initialization of ui-data if not there? 为什么会这样?如果不存在,如何处理ui数据的初始化?

I would have expected onRestoreInstanceState before onCreate. 我本来希望onCreate之前有onRestoreInstanceState。

The documentation for onRestoreInstanceState() clearly states: onRestoreInstanceState()文档明确指出:

This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. 当活动从先前保存的状态重新初始化时,在onStart()之后调用此方法(在此处已保存状态)。 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. 大多数实现将仅使用onCreate(Bundle)来恢复其状态,但是在完成所有初始化或允许子类决定是否使用默认实现之后,有时在此处执行此操作很方便。

If you wish to initialize your UI with stuff from the Bundle in onCreate() , feel free to do so. 如果您希望使用onCreate() Bundle中的内容来初始化UI,请随时进行初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 onRestoreInstanceState-Android视图生命周期 - onRestoreInstanceState - Android View Lifecycle 什么时候不调用 onRestoreInstanceState? - When onRestoreInstanceState is not called? 什么时候调用 onRestoreInstanceState? - when is onRestoreInstanceState called? onRestoreInstanceState()在预期时不被调用 - onRestoreInstanceState() not being called when it is expected 什么时候调用onSaveInstanceState()和onRestoreInstanceState()? - When exactly are onSaveInstanceState() and onRestoreInstanceState() called? 手机关机时的AlarmManager - ANDROID - AlarmManager when the phone is turned off - ANDROID 在android中实现Parcelable时,不会调用onRestoreInstanceState - implementing Parcelable in android, onRestoreInstanceState is not getting called Android生命周期函数onRestoreInstanceState、onSaveInstanceState用例 - Use-case of Android Lifecycle functions onRestoreInstanceState, onSaveInstanceState Android:屏幕唤醒(和锁定)后未调用onRestoreInstanceState - Android: onRestoreInstanceState not called after screen wakeup (and lock) Android:在Activity生命周期中何时调用onCreateOptionsMenu? - Android: When is onCreateOptionsMenu called during Activity lifecycle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM