保存和恢复活动状态? [英] Saving and restoring activity state?

查看:201
本文介绍了保存和恢复活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经看过很多不同的方法和有关保存和恢复的状态,活动帖。我知道该怎么做了preferences,复选框,等...

So, i have looked at many different ways and posts about saving and restoring an activities state. I know how to do it for preferences, checkboxes, ect...

但是在这个示例应用程序我试图挽救一个GridView的状态。因此,在应用程序,你可以添加图片,然后长按它,并把它添加到一个单元格。基本上一个拖放。但是,当应用程序被终止,最终再重新启动,所有单元都是空的。

But in this example application i am trying to save the state of a gridview. So in the application, you can add an image then long click it and add it to a cell. Basically a drag and drop. But when the application is eventually terminated and then relaunched, all the cells are empty.

我将如何保存gridview的状态恢复之后,申请被中止?

How would i save the state of the gridview to restore after the application was "terminated"?

我使用这个源作为一个例子...的 HTTPS://blahti.word$p$pss.com/2011/10/03/drag-drop-for-android-gridview/

I am using this source as an example... https://blahti.wordpress.com/2011/10/03/drag-drop-for-android-gridview/

推荐答案

您可以让您的应用程序状态类似的HashMap 的HashMap 工具序列化接口,从而可以将其保存到捆绑通过<一个href=\"http://developer.android.com/reference/android/os/Bundle.html#putSerializable%28java.lang.String,%20java.io.Serializable%29\"相对=nofollow> putSerializable 方法。

You can keep your app state in something like HashMap. HashMap implements Serializable interface, thus it can be saved to Bundle via putSerializable method.

在此HashMap你可以保持电网的状态,例如其中绘制(其ID?)保存在每个单元格。

In this HashMap you can keep state of grid, e.g. which drawable (its id?) is saved in each cell.

这篇关于保存和恢复活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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