android - Save Activity/Fragments state custom class -


i know if there method save custom class while rotating in android app. want save instanced object called of matrixgame class...someone can me?

thanks

since fragment lifecycle independent - when you're using fragment can set doesn't destroyed upon configuration changes.

as noticed, activity class gets destroyed , re-created when rotate app (or apply other configuration changes), if want persist activity state can use sqlite , save whatever need in onpause() method. in oncreate() method check db last known state.

if want avoid saving state "forever" (meaning, user turns off app , tomorrow when turns on - want start fresh , not load last known state) can add timestamp , set threshold which, if passed, data considered stale , gets disregarded.

two comments:

  1. as @saprvade wrote, fragments gets destroyed default, in order prevent should call: setretaininstance(true)
  2. in case want implement @saprvade's other suggestion (have activity ignore rotation changes) can see following explanation of how implement: https://stackoverflow.com/a/456918/1057429

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -