java - (savedInstanceState) 是什么意思

标签 java android navigation-drawer

在我的主要 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/

相关文章:

java - ParseRole 和 ParseRelation 之间的区别

java - 动态添加编辑文本并拥有其引用

android - 您将以哪种方式设计设备之间的这种相互通信

Android ViewAnimator 和 OutOfMemoryError

java - fragment 不会在 main_activity() 中被替换

android - 抽屉导航不滑动

android - 如何检测 DrawerLayout 开始打开?

java - 如何刷新表格中的单行?

java - 线程 "main"java.lang.NullPointerException (JDBC) 中的异常

android - 在 Android 中通过 getApplicationContext() 使用静态方法?