0

In my activity, I have various fragments. By default activity displays a map. On listitem click, Fragment A, B or C is displayed using following code:

protected void replaceFragment(int i) {
    FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager
            .beginTransaction();
    switch (i) {
    case FRAGMENT_A:
        aFragment = new AFragment ();
        fragmentTransaction.replace(R.id.main_framelayout_replace,
                aFragment , TAG_A_FRAGMENT);
        fragmentTransaction.commit();
        break;//and so on.....
     default:
        break;
    }
}

Here I'm facing an issue: When I replace Fragment A with Fragment B which is nested fragment i.e. it contains list and detail fragment within itself. When I try to remove any fragment other than Fragment B, I'm able to do it successfully and show the default map screen but when I'm on Frgament B and try to remove it, I'm not able to see default map screen. Instead a blank white screen is getting displayed.

Removing of fragments is done as follows:

if (aFragment != null) {
                        fragmentManager.beginTransaction()
                                .remove(aFragment ).commit();
                    }//and so on...

For fragment B which is having list and detailed fragment, I also do following in onDetach of fragment B,

fragmentManager.beginTransaction()
                    .remove(MainActivity.listFragment).commit();

Note: I'm not getting exception in any try catch. All the lines of code are getting executed without error including onDetach of Fragment B.

Am I doing anything wrong here? Any help appreciated.

GAMA
  • 5,958
  • 14
  • 79
  • 126
  • You should inflate the `nest fragment` inside `B` and handle the logic there. Then add a interface between your `parent fragment` and it's `nest fragment` that when the `parent fragment` is removed it first removes its children. – Timothy Frisch Jul 29 '15 at 13:45
  • Check out a question I asked a while back here: http://stackoverflow.com/questions/23142956/sending-data-from-nested-fragments-to-parent-fragment – Timothy Frisch Jul 29 '15 at 13:45
  • I'm able to communicate between parent and child and fragments. And as I already mentioned, I'm removing child fragments first before removing actual fragment. – GAMA Jul 29 '15 at 13:58

0 Answers0