replace - Removing fragment issues in android -


i replacing fragment show other fragment in application.its working fine showing fragment2,but when try remove removes layouts not fragment.how remove fragment?

p.s :when click on home button fragment removed.

here code snippet

 fragment2= new myfragment(context, ls);                       bundle intent = new bundle();                       intent.putserializable("lookup_response", preparedata(5));                         lookupfragment.setarguments(intent);                       fragmenttransaction ft= ((myactivity)context).getsupportfragmentmanager().begintransaction();                       ft.replace(r.id.container, fragment2, "frahmenttag");                       ft.addtobackstack(null);                            ft.commit(); 

to remove fragment

fragmenttransaction ft = ((dashboardactivity)context).getsupportfragmentmanager().begintransaction();                         ft.remove(myfragment);                         ft.commit(); 

can me doing wrong in this?thanks

hi friends solve problem lines

 ft.add(r.id.container, fragment2, "frahmenttag");                       ft.addtobackstack(null);                            ft.commit(); 

instead of ft.replace(r.id.container, fragment2, "frahmenttag");

and when removing fragment used

 getfragmentmanager().popbackstack(); 

Comments