加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – (savedInstanceState)是什么意思

发布时间:2020-12-15 04:25:50 所属栏目:Java 来源:网络整理
导读:在我的主要活动中有一些代码说 if (savedInstanceState != null) { mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); mFromSavedInstanceState = true; 我不太明白(savedInstanceState)在这段代码中的含义.有人可以告诉我在
在我的主要活动中有一些代码说

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中的非持久性动态数据),如果需要重新创建活动(例如,方向更改),则可以将其传递回onCreate,这样您就不会丢失此先前信息.如果未提供数据,则savedInstanceState为null.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读