You could look into using Serializable
and saving the objects to files locally.
Here is oracle's tutorial on serialization using this method: Oracle tutorial link
Question
I have read some post regarding persistence methods in android
but it still unclear to me how we can persist an object?
please relate to session-persistence and application-lifetime presistence
1) persist an object as long as the app is installed => i guess it means using SQlite or sharePreferences. but I want to save an object without flattening it to key-value pairs.
2) persist an object for a session (meaning since the app is up till the user quits it) ==> I would use static variable. Any other native caching mechanism ?
Solution
You could look into using Serializable
and saving the objects to files locally.
Here is oracle's tutorial on serialization using this method: Oracle tutorial link
OTHER TIPS
The standard java way of doing that would be Serializable
, but for Android, Parcelable
is much more efficient and thus recommended.
You could use that for any object saving, be it between or while app sessions.