Chander Shivdasani
Chander Shivdasani

Reputation: 10131

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

I wanted to know, is there any other way of saving this array list between onPause and onResume?. I even tried onSaveInstanceState, but it doesnt have support for ArrayList.

Thanks, Chander

Upvotes: 0

Views: 1383

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

But, somewhere in the user defined object, i am using 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?

If it involves widgets like Button, then no.

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.

onSaveInstanceState() is solely for transient data, such as the contents of an EditText. Do not confuse this with the business data (model) for your application.

Upvotes: 1

Related Questions