Maintaining Backstack for Fragment with ChildFragments android -


i have activity calls fragment f1. fragment calls fragment f2 using below code:

fragment fragment = new f2fragment(); fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction ft = fragmentmanager.begintransaction(); ft.replace(r.id.frame_container, fragment); ft.addtobackstack("fragment"); ft.commit(); 

then fragement f2 calls fragment f3 using similar code :

fragment fragment = new f3fragment(); fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction ft = fragmentmanager.begintransaction(); ft.replace(r.id.frame_container, fragment); ft.addtobackstack("fragment"); ft.commit(); 

fragment f3 has 3 child fragments (for 3 tabs) , added using tabhost below:

public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         // todo auto-generated method stub          view rootview = inflater.inflate(r.layout.main_tab, container,                 false);          mtabhost = (fragmenttabhost) rootview                 .findviewbyid(android.r.id.tabhost);         mtabhost.setup(getactivity(), getchildfragmentmanager(),                 r.layout.main_tab);          bundle arg1 = new bundle();          arg1.putint("cf1", 1);         mtabhost.addtab(                 mtabhost.newtabspec("tab1").setindicator("cf1",                         getresources().getdrawable(r.drawable.tab_left)),                 cf1fragment, arg1);          bundle arg2 = new bundle();         arg2.putint("cf2", 2);         mtabhost.addtab(                 mtabhost.newtabspec("tab2").setindicator("cf2",                         getresources().getdrawable(r.drawable.tab_middle)),                 cf2fragment.class, arg2);          bundle arg3 = new bundle();         arg3.putint("cf3", 3);         mtabhost.addtab(                 mtabhost.newtabspec("tab3").setindicator("cf3",                         getresources().getdrawable(r.drawable.tab_rigth)),                 cf3fragment.class, arg2);          return rootview;      } 

till point working fine proper navigation. child fragment calls dialogfragment below

            confirmdialogfragment cd = new confirmdialogfragment();             cd.show(fm, "confirm fragment"); 

in dialog have button, pressing on has refresh cf1 fragmnet(from called). refreshes cf1 fragment new list issue when press button. on pressing should go f3 (from cf1 called) remains in cf1 state prior calling dialog. pressing again takes fragment f3. tried many things nothing seems working me. assume when confirm dialog called cf1 places on top of backstack, when pressed cf1 resumes state dialog fragment got called. understand if somehow isn't placed on backstack while calling dialogfragment , resolved nothing seem working of now. please advise.

use below code remove fragments backstack

fragmentmanager fragmentmanager = getsupportfragmentmanager();

            if (fragmentmanager .getbackstackentrycount() > 0){                 fragmentmanager .popbackstack();             } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -