non trivial android fragments backstack -


i'm trying implement following fragment design: fragment replaced fragment b, in turn, replaced fragment c. whether in fragment b or c, want user navigation take fragment a. add backstack when replacing b. when move b c, don't add backstack. when navigating fragment b, works fine. but, when navigating c, , c on same screen - c doesn't disappear. wonder if related backstack usage. appreciated.

my code equivalent to:

fragment fragment;  fragment = new fragmenta(); transaction.replace(r.id.container, fragment); transaction.commit();  fragment = new fragmentb(); transaction.replace(r.id.container, fragment); transaction.addtobackstack(null); transaction.commit();  fragment = new fragmentc(); transaction.replace(r.id.container, fragment); transaction.commit(); 

this general way add backstack. use tags.

fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragment1 fragment1 = new fragment1(); fragmenttransaction.replace(r.id.fragment_container, fragment1, fragment1.class.getname()); fragmenttransaction.addtobackstack(fragment1.class.getname()); fragmenttransaction.commit(); 

now similarly, frament2:

fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragment2 fragment2 = new fragment2(); fragmenttransaction.replace(r.id.fragment_container, fragment2, fragment2.class.getname()); fragmenttransaction.addtobackstack(fragment2.class.getname()); fragmenttransaction.commit(); 

do same fragment3. , remove fragment2 backstack using:

getfragmentmanager().popbackstack(     fragment2.class.getname(),      fragmentmanager.pop_back_stack_inclusive); 

you should able skip directly fragment3 fragment2.

also, using fragmenttransaction.replace(...) , not fragmenttransaction.add(...). post relevant code?


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -