如何在android中保存activity的状态?
我想知道如何保存页面(活动)的状态,因此当我返回该页面时,它应该处于我离开时的状态。 例如,如果我在页面中选中了一个复选框,那么在离开该页面后,当我回来时,应该在我离开时选中该复选框。 提前致谢
I want to know how can I save state of a page(Activity) so when I come back to that page it should be in state in which I left it.
for eg if I checked a checkbox in page so after leaving that page when I come back that checkbox should be checked as I left.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://mobile.tutsplus.com/tutorials/android/android-application- Preferences/
查看有关
SharedPreferences
或
http://developer.android.com/reference/android/content/SharedPreferences.html
http://mobile.tutsplus.com/tutorials/android/android-application-preferences/
Take a look at this tutorial about
SharedPreferences
or
http://developer.android.com/reference/android/content/SharedPreferences.html
如果您正在谈论另一个 Activity 中断当前 Activity 的情况,那么您应该考虑管理 Activity 生命周期 http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle
onSaveInstanceState()、onRestoreInstanceState() 或 onPause() 和 onResume() 中。
如果这是用于持久数据存储,则需要 SharedPreferences / DB 或某种其他形式的存储: http://developer.android.com/guide/topics/data/data-storage.html
If you are talking about a case where another Activity interrupts the current one then you should look into managing the Activity lifecycle http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle
onSaveInstanceState(), onRestoreInstanceState() or in onPause() and onResume().
If this is for persistent data storage then SharedPreferences / DB or some other form of storage would be required: http://developer.android.com/guide/topics/data/data-storage.html