gpt4 book ai didi

java - (savedInstanceState) 是什么意思

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:44 25 4
gpt4 key购买 nike

在我的主要 Activity 中有一些代码说

if (savedInstanceState != null) {
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
mFromSavedInstanceState = true;

而且我不太明白 (savedInstanceState) 在此代码中的含义。有人能告诉我这在这种情况下是什么意思吗,因为我有点菜鸟,我想了解代码,以便我可以学习、理解它,甚至在需要时复制它。

最佳答案

引自(http://developer.android.com/training/basics/activity-lifecycle/recreating.html):

There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish(). The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the foreground activity requires more resources so the system must shut down background processes to recover memory.

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

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

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