문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top