Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to serialize ArrayList on android

Tags:

android

i have a basic function which requires serializing in my android app. The user will add some values to an ArrayList and i want to serialize it to avoid using a database for this little option and of course TO LEARN how to serialize (i'm a begginer) because it seems useful. Anyways the user save something in the arraylist, the program shuts down, the program starts up again and the user is able to see the saved data. How can i implement this? Can you provide some code snippet or a useful link?

Thanks a lot!!

like image 502
madcoderz Avatar asked Jan 12 '11 15:01

madcoderz


1 Answers

You can do this by custom bean class and implement Serializable to that so now when you create ArrayList<E> of that class it is Serializable.

Example:

Class dataBean implements Serializable
{
     public String name;
}

ArrayList<dataBean> dataBeanArrayList = new ArrayList();

So dataBeanArrayList is now Serializable and you can also pass this between Intent.

like image 187
Megha Avatar answered Nov 02 '22 14:11

Megha