[英]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.