Saving and restoring activity state?

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

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...

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.

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

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

回答1:

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!