android - Error ::java.lang.IllegalStateException: Activity has been destroyed ..Fragment -


wat did : have 2 fragments . left side list displayed .rightside based on list selected fragment wil created ..

expected output : when click button on right fragment . fragment should closed , other fragment should displayed

error occurring :error ::java.lang.illegalstateexception: activity has been destroyed

public void managefragment(int id, int fragmentid, boolean backstack) {

    fragmentmanager fragmentmanager = getsupportfragmentmanager();     fragmenttransaction fragmenttransaction = fragmentmanager             .begintransaction();      switch (id) {      case 0:         1 o = new one();         fragmenttransaction.remove(getsupportfragmentmanager().findfragmentbytag(                 tag));         fragmenttransaction.add(fragmentid, o, "one");         tag = "one";         break;     case 1:         2 t = new two();         fragmenttransaction.remove(getsupportfragmentmanager().findfragmentbytag(                 tag));         fragmenttransaction.add(fragmentid, t, "two");         tag = "two";         break;     case 2:         3 thr = new three();         fragmenttransaction.remove(getsupportfragmentmanager().findfragmentbytag(tag));         fragmenttransaction.add(fragmentid, thr, "three");         tag = "three";         break;     case 3:         4 f = new four();         fragmenttransaction.remove(getsupportfragmentmanager().findfragmentbytag(                 tag));         fragmenttransaction.add(fragmentid, f, "four");         tag = "four";         break;     case 4:          5 fiv = new five();         fragmenttransaction.remove(getsupportfragmentmanager().findfragmentbytag(                 tag));         fragmenttransaction.add(fragmentid, fiv, "five");         tag = "five";         break;     }     if(backstack){         fragmenttransaction.addtobackstack(null);     }      fragmenttransaction.commit(); } public void setdetails(int id) {     if (findviewbyid(r.id.listfragmenttablet) != null) {         managefragment(id, r.id.detailsfragmenttablet, false);      } else {         removelistfragment();         managefragment(id, r.id.fragmentphone, true);     }  } 

this mainactivity class .i call setdetails function when left list clicked . based on position right side fragment change .

public class 1 extends fragment {     @override    public view oncreateview(layoutinflater inflater, final viewgroup container,              bundle savedinstancestate) {         view view =inflater.inflate(r.layout.one, container, false);       button bt=(button)view.findviewbyid(r.id.onelayout);       bt.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 simplemethod() ;             }           });       return view;   }    private void simplemethod() {         // todo auto-generated method stub //  getactivity().getsupportfragmentmanager().begintransaction().remove(this).commit();     new mainactivity().managefragment(2, r.id.detailsfragmenttablet, false);     //new mainactivity().setdetails(3);      } 

this detailed fragment . when click button should remove , fragment should show

    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" >  <linearlayout     android:id="@+id/listfragmenttablet"     android:layout_width="0dp"     android:layout_height="match_parent"     android:layout_weight="2"     android:orientation="horizontal" />  <linearlayout     android:id="@+id/detailsfragmenttablet"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_weight="3"     android:orientation="horizontal" > </linearlayout> 

this mainlayout layoutfile


Comments