使用的onSaveInstanceState(包..)和onRestoreInstanceState(包..)
是非常好的工作,但在工作时点击关闭按钮模拟器。
现在,我想保存状态,并恢复保存的数据时,下面的按钮用于:
using onSaveInstanceState(Bundle ..) and onRestoreInstanceState(Bundle ..)
was really good and work, but it is working when click Turn off button on Emulator.
Now, i want to save state and restore the saved data when below button used:
我认为这是可能的使用将OnPause()或oOnStop(),如果我是正确的,如何使用它, 这将是足以让我保存一个布尔变量的Java源代码,并恢复它, 谢谢你。
I think it is possible to use OnPause() OR oOnStop(), if i am right, How to use it, it will be enough to show me Java source of saving one boolean variable, and restore it, Thanks.
我会使用的onPause()
,因为的onStop()
不能保证被调用。请参阅应用程序基础有关生命周期的详细信息。
I would use onPause()
, as onStop()
is not guaranteed to be called. See the application fundamentals for details on the lifecycle.
要保存和恢复一个布尔值,我会用共享preferences
。有在数据存储页面一个code为例它展示了如何保存和恢复一个布尔值。他们使用的onCreate()
和的onStop()
,但我会用 onResume()
和的onPause()
,因为我已经提到的原因。
To save and restore a boolean, I would use SharedPreferences
. There is a code example on the data storage page that shows how to save and restore a boolean. They use onCreate()
and onStop()
, but I would use onResume()
and onPause()
, for the reasons I have already mentioned.
上一篇:在C#中,我怎么能知道编程如果操作系统是基于x64或x86操作系统、是基于、我怎么能
下一篇:简单的非API的Android的JUnit在Eclipse测试与Android,Maven的插件?插件、简单、测试、Andr