Android: How to remove fragments from backstack? -
i have situation want clear fragments backstack except 1 visible(i.e. on top)
for example, there 4 fragments in backstack a->b->c->d (d on top)
now want remove fragments a,b,c backstack. constraint there should not visible effect on fragment d while removing history backstack.
this code.
fragmentmanager fm = getactivity().getsupportfragmentmanager(); bundle bundle = new bundle(); orderreceiptfragment orderreceiptfragment = new orderreceiptfragment(); bundle.putserializable("orderhistory", orderhistory); orderreceiptfragment.setarguments(bundle); commonutil.clearbackstack(fm); fm.begintransaction().setcustomanimations(r.anim.enter_from_left, r.anim.exit_to_right) .replace(r.id.container, orderreceiptfragment).commit();
method clearbackstack
public static void clearbackstack(fragmentmanager fragmentmanager) { fragmentmanager.popbackstack(0, fragmentmanager.pop_back_stack_inclusive); }
here problem - while clearing backstack, milliseconds first fragment backstack gets visible. looks weird. have solution this?
you can
mehtod 1 :: removing 1 one
fragmentmanager fm = getactivity().getsupportfragmentmanager(); (int = 0; < fm.getbackstackentrycount(); ++i) { fm.popbackstack(); }
mehthod 2
fragmentmanager fm = getactivity().getsupportfragmentmanager(); fm .popbackstack(null, fragmentmanager.pop_back_stack_inclusive)
see answer. can find different methods
also refer popbackstackimmediate
Comments
Post a Comment