为什么onRestoreInstanceState()不会被调用 [英] Why onRestoreInstanceState() never gets called

查看:700
本文介绍了为什么onRestoreInstanceState()不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据保存在我的活动,比恢复。 我保存的数据的onSaveInstanceState(),然后我试图恢复 onRestoreInstanceState数据()

I am trying to save data in my activity and than restore it. I save data in on onSaveInstanceState() and then I try to restore the data in onRestoreInstanceState().

我设置断点,该方法的onSaveInstanceState()被调用。但 onRestoreInstanceState()的onCreate()从来没有。

I setup breakpoint, the method onSaveInstanceState() get called. But onRestoreInstanceState() or onCreate() never did.

下面是我的步骤:

  1. 在开始我的活动
  2. preSS'家'的手机上的按钮。 的onSaveInstanceState()被调用。
  3. 单击在发射器的图标和再次启动我的活动。
  1. start my Activity.
  2. press 'Home' button on the phone. onSaveInstanceState() get called.
  3. Click the icon in the launcher and launch my Activity again.

在这个时候,只有 onRestart()被调用。但是,并非 onRestoreInstanceState()的onCreate()

At this time, only onRestart() get called. But not onRestoreInstanceState() or onCreate().

有谁知道为什么吗?

推荐答案

那么,如果 onRestart()被调用时,实例变量的值将由维护应用程序栈本身,因此你不需要恢复它们。

Well, if onRestart() is called, the value of the instance variables would be maintained by the application stack itself and thus you do not need to restore them.

的onCreate()只调用了,当你的活动的onStop() 被调用,进程被杀死。

onCreate() method is only called when your Activity's onStop() is called and the process is killed.

请参照活动生命周期中的 Android的活动生命周期获得一个清晰的认识。

Please refer the Activity life cycle Android Activity Life Cycle for a clear understanding.

您可能要检查的onStop()方法是否被调用,如果你的进程被终止。我不认为你的过程中被杀害,你所描述的情景。

You may want to check whether the onStop() method is called and if your process is killed. I do no think that your process gets killed by the scenario which you have described.

onRestoreInstanceState()方法是非常棘手的。我不知道什么时候正是它叫,但我看到了,而从Potrait改变为横向,它被称为一次。

the onRestoreInstanceState() method is very tricky. I do not know when exactly it is called but I saw it was called once while changing from Potrait to Landscape.

这篇关于为什么onRestoreInstanceState()不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆