android - Clear fragment stack to go to another single one -


i'm opening fragments containing list, on , on again, then, ultimately, want clear fragment stack open new fragment once reach end of fragments containing list.

i don't know if i'm being clear here i'm doing currently:

private final broadcastreceiver onreceivelaunchincident = new broadcastreceiver() {          @override         public void onreceive(context context, intent intent) {             getsupportfragmentmanager().popbackstack(null, fragmentmanager.pop_back_stack_inclusive);             // select correct item drawerlayout             selectitem(drawerlist.indexof("patrol"));          }     }; 

currently goes way when enter broadcastreceiver

fragment d ---> fragment a ---> fragment e

and want go way:

fragment d ---> fragment e

enter image description here

private void selectitem(final int position) {     addtodrawerifnotexist(position);      if (mdrawerlistchild.getcheckeditemposition() == position) {         log.i(tag, "same position selected in drawer");     }      mdrawerlistchild.setitemchecked(position, true);     mdrawerlayout.closedrawer(mdrawerlinear);     new handler().postdelayed(new runnable() {         @override         public void run() {             fragmenttransaction ft = getsupportfragmentmanager().begintransaction();             ft.setcustomanimations(r.anim.fade_in, r.anim.fade_out, r.anim.fade_in, r.anim.fade_out);             backhandledfragment fragment = fragmentliststring.get(fragmentlist.get(position));              ft.replace(r.id.content_frame, fragment, fragment.gettagtext())                     .commitallowingstateloss();         }     }, 300); } 

you having problem because of way have added first fragment. if think backstack record of transactions instead of fragments can see why left fragment a. when add fragment i'm guessing not setting first transaction included in backstack. if case first entry have in stack change b being undone when perform pop code above. problem should resolved adding first entry backstack using addtobackstack call during transaction.

the code example below uses transaction replace allow still not add fragment stack suggested above. replace call not included in stack , replace fragment e while leaving stack empty.

edit

private void selectitem(final int position) {     addtodrawerifnotexist(position);      if (mdrawerlistchild.getcheckeditemposition() == position) {         log.i(tag, "same position selected in drawer");     }      mdrawerlistchild.setitemchecked(position, true);     mdrawerlayout.closedrawer(mdrawerlinear);      fragmenttransaction ft =  getsupportfragmentmanager().begintransaction();     backhandledfragment fragment = fragmentliststring.get(fragmentlist.get(position));      ft.replace(r.id.content_frame, fragment, fragment.gettagtext()).commit(); } 

edit 2: removed fade animation because causing flicker see fragment split second before transition fragment e.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -