I have implemented a fragment container to change fragments inside my tabs. (see: [android, dynamically change a fragment inside a tab](https://stackoverflow.com/questions/14887065/android-dynamically-change-a-fragment-inside-a-tab))

I'm using a fragment tab host, and a framelayout (that its on a separate activity) to load my fragments into it. I have a button in my fragment that is changing into another Fragment. I've implemented that method, and I resolve the overlapping fragment problem. the thing is, that now, every time I press the back button my app exits (no matter where my fragment is).

I have checked that I a have the `tx.addToBackStack(curFrag.getClass().getSimpleName())` even tried with `tx.addBackStack(null)` before the commits, but still doesnt do anything. Could anyone help me? thank you.

Edited:

I'm already adding a tag to my tabhost.
this is my FragmentTabMenu.java

```
setContentView(R.layout.activity_fragment_tab_menu);
        Resources res = getResources();

        mtabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); //id from the activity that hosts the tabwidget
           mtabHost.setup(this, getSupportFragmentManager(), R.id.FrameLayout1); //id from the other activity that only hosts the framelayout

           //passing the class that my container will execute on the onResume method 

           Bundle args1=new Bundle();              
           args1.putSerializable(PARAM_CONTENT_FRAGMENT,RegistoUtilizador.class); 

           //creating the tab
           mtabHost.addTab(
                    mtabHost.newTabSpec("RegistoUti").setIndicator("Tab 1",
                            res.getDrawable(R.drawable.tab_icon_rui)),
                    ContentorFragRegistoUti.class, args1);

```

And this is my container class

```
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

   return inflater.inflate(R.layout.frag_container, null);
}

public void replaceContent(Class<? extends Fragment> clz, Bundle args) {
    FragmentTransaction tx = getChildFragmentManager().beginTransaction();

    tx.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    // save
    Fragment curFrag = getChildFragmentManager().findFragmentById(R.id.FrameLayout1);
    tx.addToBackStack(curFrag.getClass().getSimpleName());

    // change
    try {

        Fragment newFragment = clz.newInstance();
        newFragment.setArguments(args);
        tx.replace(R.id.FrameLayout1, newFragment, clz.getClass().getSimpleName());

        tx.commit();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

@Override
public void onResume() {
    super.onResume();
    Fragment f = getChildFragmentManager().findFragmentById(R.id.FrameLayout1);
    if (f == null) {
        Class<? extends Fragment> claz = (Class<? extends Fragment>) getArguments().getSerializable(
                PARAM_CONTENT_FRAGMENT);

      FragmentTransaction tx = getChildFragmentManager().beginTransaction();
        try {
            f = claz.newInstance();
            f.setTargetFragment(this, 0);
            tx.add(R.id.FrameLayout1, f);
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }
}

```

Maybe i missunderstood what Framelayout id, i should be calling on my methods?