I have an ArrayList
with custom objects. Each custom object contains a variety of strings and numbers. I need the array to stick around even if the user leaves
For String, int, boolean, the best choice would be sharedPreferences.
If you want to store ArrayList or any complex data. The best choice would be Paper library.
Add dependency
implementation 'io.paperdb:paperdb:2.6'
Initialize Paper
Should be initialized once in Application.onCreate():
Paper.init(context);
Save
List contacts = ...
Paper.book().write("contacts", contacts);
Loading Data
Use default values if object doesn't exist in the storage.
List contacts = Paper.book().read("contacts", new ArrayList<>());
Here you go.
https://github.com/pilgr/Paper