How can I save an arrayList permanently without database.
If you could include an example it would be great.
Thank you!
How can I save an arrayList permanently without database.
If you could include an example it would be great.
Thank you!
If it's just the one ArrayList and you don't have any complex ordering to your datastore, I would just save it out internal storage in binary format. That will save you a lot of overhead trying to encode and decode the file in a text format such as XML or JSON.
A link to check out is Data Storage.
Edit: I put together a quick and dirty github repo to give an example. It's not something I would just copy and paste into a project, but it should show you the basic mechanics.
Edit 2: Note that all the Objects inside the ArrayList need to implement Serializable or be primitive types for this to work.
Export the ArrayList to a file maybe in a specific format ( Xml,JSON,csv etc. ) Then ready upon the data when you need it.
Pseudo:
String data;
i = 0;
Loop Array
data += array[i]
i++;
End loop
Write data to file
You can make it as easy/hard as you want ofc. But you get the idea i think :)
Have you seen this example?
But you will lose data after a switchoff or restart.
You can use the Serialize stuff from Java. The objects inside the ArrayList
should implement the Serializble Object. Than, you can save the resulting binary file to storage and reload it. here's an example of how to do it: http://www.jondev.net/articles/Android_Serialization_Example_%28Java%29