如何序列化ArrayList的android上 [英] how to serialize ArrayList on android

查看:171
本文介绍了如何序列化ArrayList的android上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的功能,需要在我的Andr​​oid应用程序序列化。用户将添加一些值到一个ArrayList,我想序列化,以避免使用数据库来实现,当然这个小选项,并学习如何序列化(我是初学者),因为它似乎是有用的。不管怎么说用户保存的东西ArrayList中,该程序关闭,程序再次启动,用户能够看到保存的数据。我怎样才能实现呢?你能否提供一些code片段或有用的链接?

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?

非常感谢!

推荐答案

您可以通过自定义bean类做到这一点,实施序列化到 所以现在当您创建的ArrayList< E> 该类它是序列化

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.

例如:

Class dataBean implements Serializable
{
     public String name;
}

ArrayList<dataBean> dataBeanArrayList = new ArrayList();

所以 dataBeanArrayList 现在序列化,你也可以在通过这个意图

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

这篇关于如何序列化ArrayList的android上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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