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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -