android - save view instance of fragment in backstack -
android - save view instance of fragment in backstack -
i've read topic save instance state of fragment. think case different.
example: have fragment a, b. have edit text. type text edit text add together fragment b backstack.
then popbackstack fragment b => display.
but edittext empty.
here way fixed:
private class myfragment extends fragment { private view rootview = null; @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { if (rootview != null) { ((windowmanager) rootview.getparent()).removeview(rootview); } else { view v = inflater.inflate(r.layout.my_layout, container, false); // find view layout. rootview = v; } homecoming rootview; } }
it's auto maintain lastest state of fragment.
but here question:
does app spend much memory normal ? (because create new rootview save instance of view of fragment.) care how ondestroyview working in case ? if android scheme auto destroy view free memory -> why rootview variable still maintain instance ?
if android scheme don't kill rootview variable => create view medittextinput, mimageviewavatar.... reference "id" in layout => bad ?
(notes: rootview <=> variable save instance of root view of fragment.)
android performance android-fragments
Comments
Post a Comment