Code example for FragmentManager

Methods: getBackStackEntryCount

0
        startActivity(intent);
    } 
 
    public void finishFragmentOrActivity(View v) {
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0)
            getSupportFragmentManager().popBackStack(); 
        else 
            finish(); 
    } 
 
    public void launchNewFragment(View v) {
        addFragment(new ExampleFragment(), true, FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    } 
}