android - Fragment navigation -
i'm creating app, 1 main activity , fragments. i'm trying control happen on backpress using code on mainactivity:
@override public void onbackpressed() { if (getfragmentmanager().getbackstackentrycount() == 0) { this.finish(); } else { getfragmentmanager().popbackstack(); } }
the structure of app this: mainativity --> fragment1 --> fragment2 --> fragment2 ... (back press should me fragment1)
when created fragment2 added fragment1 backstack, , when pressing still see fragment2 in background. how can fragment1 , fragment1 show?
i'm not sure how commit fragment. helpful.
while commit:
// initialize fragment transaction. fragmenttransaction ft = getsupportfragmentmanager().begintransaction(); // record steps transaction. ft.replace(r.id.home_frame_layout_for_fragments, basefragments[i], // add transaction backstack tag of first added fragment ft.addtobackstack(basefragments[0].gettagtext()); // commit transaction. ft.commit();
while removing:
final fragmentmanager fragmentmanager = getsupportfragmentmanager(); while (fragmentmanager.getbackstackentrycount() != 0) { fragmentmanager.popbackstackimmediate(); }
this may works !!!
happy coding !!!!
Comments
Post a Comment