微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – (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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐