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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
Your general options are either to use a database (perhaps actually getting rid of the
ArrayListin the first place) or persistence to a file (serialization, XML, JSON, etc.).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
ArrayListmight store that might not work well in a database. Of course, there are things yourArrayListmight store that might not even be able to be persisted at all (e.g., a socket, a widget).