0

I have an app with child fragments nested inside another fragment using AppCompatActivity. The child fragment is created as follows:

        FragmentManager fragmentManager = getChildFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        SeriesFragment seriesFragment =SeriesFragment.newInstance();

        fragmentTransaction.replace(container.getId(), seriesFragment);
        fragmentTransaction.addToBackStack("seriesFragment");
        fragmentTransaction.commit();

The onBackPressed method in the activity is not triggered only when the child fragment is displayed. The app just exits instead of returning to the previous screen. No idea why. Any help is greatly appreciated.

Jaz
  • 371
  • 1
  • 6
  • 20
  • Have you seen any error msg in your logcat ? – Long Ranger Aug 19 '16 at 03:26
  • I think you are destroying your previous activity( calling finish() may be) . onBackPressed is only a callback to tell the system that the device hard back button is pressed. The previous activity should restore even without this callback getting called. Please post the code how the activity is getting called – V_Coder_Z Aug 19 '16 at 03:30
  • @ V_Coder_Z it is right, possibly the app crash may be occurred by "Memory leak", "Exception" or the simple thing "Only one activity in current stack and it is finished" (which means normal exit) – Long Ranger Aug 19 '16 at 03:35
  • Hi, no error in the logcat which is strange and the activity is definitely still active. Strange thing I found is that if I click on any of the views before the back button it works correctly but if not it disappears. In know it's tough without seeing all the code so thanks for your suggestions anyway. – Jaz Aug 19 '16 at 19:52

0 Answers0