gpt4 book ai didi

android - 什么是 onCreate(Bundle savedInstanceState)

转载 作者:IT老高 更新时间:2023-10-28 13:01:54 27 4
gpt4 key购买 nike

谁能帮我了解 onCreate(Bundle savedInstanceState) 中的 Bundle savedInstanceState 我是 Android 新手。我尝试从 developer.android.com 了解它。但我无法理解。谁能简化一下?

最佳答案

如果您将应用程序的状态保存在一个包中(通常是非持久的、动态的数据在 onSaveInstanceState 中),它可以被传递回 onCreate 如果 Activity 需要重新创建(例如,方向更改),这样您就不会丢失此先验信息。如果未提供数据,则 savedInstanceState 为空。

... you should use the onPause() method to write any persistent data (such as user edits) to storage. In addition, the method onSaveInstanceState(Bundle) is called before placing the activity in such a background state, allowing you to save away any dynamic instance state in your activity into the given Bundle, to be later received in onCreate(Bundle) if the activity needs to be re-created. See the Process Lifecycle section for more information on how the lifecycle of a process is tied to the activities it is hosting. Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks, so will not be called in every situation as described in its documentation.

source

关于android - 什么是 onCreate(Bundle savedInstanceState),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10810418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com