Nested Fragments and ViewPager issues on Android -
i using fragmentstatepageradapter in combination view pager, nested in fragment on android. thus, using childfragmentmanager in combination fragmentstatepageradapter create fragments.
so far good, here problem:
if open different activity without finishing activity hosts fragment view pager , afterwards resume it, fragment selected in viewpager empty. if switch fragment in viewpager before open different activity, issue not appear. after returning , seeing empty fragment in viewpager, still able switch next fragments, if seek switch empty fragment, nullpointerexception. issue not occur if switch between fragment hosting viewpager , different fragment or if alter orientations.
if utilize fragmentmanager instead of childfragmentmanager, not have issue when switching different activity, occur if switch between hosting , different fragment or if alter orientation.
so here's tried without success: * utilize fragmentstatepageradapter adapter , fragmentpageradapter * utilize setretainedinstance(true , false) * utilize getchildfragmentmanager() , getfragmentmanager() * override getitemposition() homecoming postion_none , utilize notifydatachanged() in onresume()
the thing doing trick recreating pageradapter in onresume() , re-initializing viewpager, think that's bad practice needs recreated.
so there somebody, can explain me how right implementation should like, or why fragments can become empty (they not null, checked that). searching more elegant solution rather recreating each time resume activity.
any help appreciated.
android android-fragments android-viewpager fragmentpageradapter
No comments:
Post a Comment