android - Save & restore Fragment's UI state when pushed and poped out of the backstack -
background:
i have main activity, wraps main fragment can changed, , in order maintain backstack utilize fragmentmanager's backstack.
the main difference keeping activity stack when fragment pushed backstack , replaced phone call it's ondestroyview() not it's ondestroy(), , when it's view re-created oncreateview(). (however oncreate() not called fragment object not disposed)
in activity stack won't happen , views remain.
this has positive effect on low-end devices android os can free memory , don't have maintain views right (in app messages server might alter view in time) 1 can save precious bandwidth well.
the actual problem:
let's have fragment , user click on , it's view changed, e.g. list expanded.
if user go screen (i.e. fragment) previous fragment pushed backstack , it's view destroyed.
when user going back, fragment re-created , not "remember" changes user had made, e.g. list not expanded should
so how can save state , restore without making special cases every view?
undesired answers:
keep view alive: doing maintain view break fragment efficiency usingonsaveinstancestate(): not called when fragment pushed backstack activity not destroyed , that's not configuration change. special object: prefer not if there way scheme can you. android android-fragments back-stack savestate fragmentmanager
No comments:
Post a Comment