如何使用的onPause与Android? [英] How to use onPause with Android?

查看:126
本文介绍了如何使用的onPause与Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用的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.

这篇关于如何使用的onPause与Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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