android - OnSaveInstanceState/OnRestoreInstanceState with java collections -
is approach save java collections when using onsaveinstancestate/onrestoreinstancestate
flow?
i have activity populates information using java collections (for example arraylist
containing objects of type a). information populated in listview
, normal android applications do. additionally, each row start detail activity result (startactivityforresult(...)
) , expected updates when returns (using onactivityresult).
for testing purposes, enabled "don't keep activities" on device developer preferences see if application crashes. logically, when parent activity removed, objects gone. when return activity (onactivityresult
executed) list empty/null.
my question is, approach save list in onsaveinstancestate
, restore on onrestoreinstancestate
method in order prevent empty lists or enough check if list null on onactivityresult
method? depend on activities logic? or practice save items used on onactivityresult
method?
well if don't app crashes right? :)
think it's approach save objects onsaveinstancestate
because android
restore views
layout logic, not data model logic, that's you. , don't forget experiencing in onactivityresult
if app goes background let's receive phone call, when back, onresume
called , data model null @ point too. activity life-cycle onsaveinstancestate
, onrestoreinstancestate
should implemented if need persist data model. of course depend on logic because if fetch data in onresume
you'll never have issue.
more here: onsaveinstancestate , onrestoreinstancestate
ps: objects
need implement serializable
or parcelable
Comments
Post a Comment