There is an Activity whith FrameLayout.
I need:
1.add(replace) fragment A in Activity
2.add picture in ImageView in fragmet A (an example by button onclick)
3.replace in container fragment A to fragment B
4.if i press button Back on device, I will see fragment A without Image (and other changes )
I used this code to replace fragments
 FragmentManager fragmentManager = getSupportFragmentManager ();
 FragmentTransaction transaction = fragmentManager.beginTransaction ();
 transaction.replace (R.id.container, fragmentB, tag) .addToBackStack (null) .commit ();
In Activity there is a code:
 @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            FragmentManager manager = getSupportFragmentManager();
            int count = manager.getBackStackEntryCount();
            if(count==0) {
                super.onBackPressed();
            }else{
                manager.popBackStack();
            }
        }
    }
If you do the same things with two activities-there are no problems. Image exists on screen after button Back was pressed.
what did I do wrong?
 
     
    