Search code examples
androidandroid-intentarraylistrobustness

Storing array list in memory on android app (in a robust manner)


I'm working on a android app (to work with old androids as well as new, so no 3.0 tricks), and I'd like to store submit data in an arrayList in my app, that can be shared across views. The data is first stored instantiated into an object, then it will be an arrayList. I'd like to have access across views, (sharedPref maybe?) but I also need to make sure if the app crashes the rest of the data is not erased.

Any suggestions?


Solution

  • Here's a really good tutorial for getting an SQLite database setup and understanding how it works, which also includes a pretty good helper class you can modify to fit your needs:

    http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android

    In my comment, I was trying to explain that if you have an ArrayList of Objects, you can store each object in the database, and then re-populate your ArrayList using that.

    IE. You have a Objects A and B with an int ID and a String name. Store each object's ID, name, etc., in the database. When you go to pull them back out, re-create your object (IE. A/B) from the values stored (IE. ID/name), and then add them to an ArrayList containing all your Objects of that type.

    Hopefully I explained that well enough, but either way, that link I provided will definitely point you in the right direction