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.

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...