java - Replacing Main Fragment from its Child Fragment -
i'm trying replace mainfragment other fragment childfragment of mainfragment. using part of code:
android.support.v4.app.fragmentmanager fragmentmanager = getfragmentmanager(); fragment fragment = null; fragment = mainfragment2.class.newinstance(); fragmentmanager.begintransaction().replace(r.id.flcontent, fragment).commit(); fragmentmanager.executependingtransactions(); problem is, mainfragment get's destroyed , replacing successful, problem child of mainfragment never gets destroyed , child methods(destroy, pause, stop..) never called(i need methods). remain in memory , when getting between activities in app onresume() method of child fragment gets called. strange. i'm doing wrong here?
create interface :
interface mainnavigaton { void replacefragment(); } on main activity
class activity exteds... implements mainnavigation public void replacefragment() { //replace fragment here. } all childs used activity :
private mainnavigation mainnav; public void onattach(context context) { mainnav = (mainnavigation) context; } replace fragment want.
action.onclicklistner(new view.onclicklistneer() { mainnav.replacefragment(); }
Comments
Post a Comment