简体   繁体   English

Android:在onPause和onResume之间保存用户定义对象的ArrayList

[英]Android: Saving ArrayList of User Defined Objects between onPause and onResume

I am working on an application where i am saving the state of an application in an ArrayList. 我正在将应用程序的状态保存在ArrayList中的应用程序上。 Now, to save this state, i tried to use Serialization. 现在,为了保存此状态,我尝试使用序列化。 But, somewhere in the user defined object, i am using Button, which is not letting me serialize the entire object. 但是,在用户定义的对象中的某处,我正在使用Button,这不能让我序列化整个对象。

I wanted to know, is there any other way of saving this array list between onPause and onResume?. 我想知道,还有其他方法可以在onPause和onResume之间保存此数组列表吗? I even tried onSaveInstanceState, but it doesnt have support for ArrayList. 我什至尝试过onSaveInstanceState,但它不支持ArrayList。

Thanks, Chander 谢谢,钱德

But, somewhere in the user defined object, i am using Button 但是,在用户定义的对象中的某处,我正在使用Button

Never mix your models and views. 切勿混淆模型和视图。 Please redesign your "state" to be pure model data. 请重新设计您的“状态”为纯模型数据。

I wanted to know, is there any other way of saving this array list between onPause and onResume? 我想知道,还有其他方法可以在onPause和onResume之间保存此数组列表吗?

If it involves widgets like Button , then no. 如果涉及诸如Button小部件,则否。

Once you clean up your state, you can persist it to a database, or persist it to a JSON/XML file, or serialize it to a file, or whatever. 清理状态后,您可以将其持久化到数据库,或持久化到JSON / XML文件,或将其序列化到文件,等等。

onSaveInstanceState() is solely for transient data, such as the contents of an EditText . onSaveInstanceState()仅用于瞬态数据,例如EditText的内容。 Do not confuse this with the business data (model) for your application. 不要将此与您的应用程序的业务数据(模型)混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM