什么是保存一个ArrayList内容的最佳方式?

什么是保存一个ArrayList内容的最佳方式?

问题描述:

我要救一个ArrayList,使其具有持久性。的内容可以改变。什么是android系统中处理这个的最佳方式?

I want to save an ArrayList so that it is persistent. The contents can change. What is the best way of approaching this in android?

您的问题是类似的问:我有这个袋子的东西 - 我的东西转移到一个箱子,水桶,桶,或BIN。

Your question is akin to asking "I have this bag of stuff -- should I transfer the stuff to a box, bucket, barrel, or bin?".

不知道是什么东西是,我们不能轻易回答的问题。

Without knowing what the "stuff" is, we cannot easily answer the question.

您一般的选项是使用一个数据库(也许实际上得到摆在首位摆脱的ArrayList ),或持久性文件(系列化,XML,JSON,等等)。

Your general options are either to use a database (perhaps actually getting rid of the ArrayList in the first place) or persistence to a file (serialization, XML, JSON, etc.).

一般来说,一个SQLite数据库具有优势,那就是使用交易和一般比只是写自己的文件更加健壮。然而,有些事情你的的ArrayList 可能存储可能无法在数据库中很好地工作。当然,有一些事情你的的ArrayList 可能存储可能甚至无法在被持久化所有的(例如,一个插座,一个widget)。

Generally speaking, a SQLite database has advantages, in that is uses transactions and will be generally more robust than just writing your own file. However, there are things your ArrayList might store that might not work well in a database. Of course, there are things your ArrayList might store that might not even be able to be persisted at all (e.g., a socket, a widget).