Reputation: 2362
I have following ArrayList in Android:
private ArrayList<Integer> Array= new ArrayList<Integer>();
It will grow over time via add() It will approximately contain up to 50 elements.
I want to store it persistent. I was thinking of xml, sharedpreferences and DB, but I am not sure what is the best way to go.
Upvotes: 3
Views: 7186
Reputation: 2062
I would use whatever else you are using in your app - ie keep similar things in similar places.
One benefit of using sharedpreferences is that they can be backed up (if you implement that service)... However using a DB may give you more flexibility in the future.
That doesn't really answer the question though. From how you describe it, it does smell like preferences would be better though.
Upvotes: 0
Reputation: 8072
Saving to SharedPrefs is probably the quickest.
Here is a question that shows how to marshal an array of strings into json and then store in SharedPreferences (and read them back again).
Just change the String array to an Integer array and you're done.
How can write code to make sharedpreferences for array in android?
Upvotes: 5