I made a very simple Activity which shows a simple ListFragment like below:
My Activity:
public class MyActivity ex
If any one come across similar type of issue:
I was facing same time of issue, but in my case from Main Activity I was calling to Fragment1 and then if user click on Fragment1 Layout I want to launch another Fragment2 Layout.
I was able to launch Fragment1 from Main activity but Fragment1 to Fragment2 it was failing with exception as "Activity has been destroyed" .
I resolved above issue by maintaining FragmentManager object as static in MainActivity class. private static FragmentManager mfragmentManager = null;
calling to both fragment using same above object, resolved my issue.
Below is my Fragment switching code from Main Activity.
public void switchToFragment(String fragmentName){
Fragment fragment = null;
switch (fragmentName) {
case "Fragment1":{
fragment = new Fragment1();
break;
}
case "Fragment2": {
fragment = new Fragment2();
break;
}
}
FragmentTransaction transaction = mfragmentManager.beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.commit();
}