java - Handling FragmentTransaction - addToBackStack() -


i working on app has activity , fragment structure shown below:

enter image description here

i couldn't implement fragmenttransactionin such way when press button in phone can go previous fragments. so, series begins in subfragment1 , ends in secondactivity:
subfragment1->subfragment2->subfragment3->secondactivity

handling framgnettransaction stuff inside fragmentb:

//this part inside oncreateview of fragmentb fragmenttransaction fragmenttransaction = getchildfragmentmanager().begintransaction(); fragmenttransaction.add(r.id.container, subfragment1(), fragment_sub1); fragmenttransaction.addtobackstack("first"); fragmenttransaction.commit(); }  public void gotosubfragment2(){     fragmenttransaction fragmenttransaction = getchildfragmentmanager().begintransaction();     fragmenttransaction.replace(r.id.container, subfragment2(), fragment_sub2);     fragmenttransaction.addtobackstack("second");     fragmenttransaction.commit(); }  public void gotosubfragment3(){     fragmenttransaction fragmenttransaction = getchildfragmentmanager().begintransaction();     fragmenttransaction.replace(r.id.container, subfragment3(), fragment_sub3);     fragmenttransaction.addtobackstack("three");     fragmenttransaction.commit(); } 

when want go next subfragment inside subfragment, use:

   ((fragmentb) this.getparentfragment()).gotosubfragment2(); 

and finally, in subfragment3, use code below go secondactivity:

intent intent = new intent(getcontext(), secondactivity.class); getcontext().startactivity(intent); 


so, happens when press button... if in 1 of subfragments, closes app. if i'm in secondactivity , press button, app crashes , in logcat says

unable resume activity {com.app_name.mainactivity1}: java.lang.illegalstateexception: executed. 

in conclusion, question is: doing wrong? considered wrong handle fragmenttransaction stuff inside fragment? if so, correct way? correct way add actions backstack. why button not working properly?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -