I had the same problem as you, but I realized that you had to deal with the back button in the activity where you are running your fragments from. You need to override the onBackPressed()
in the activity code, not inside the fragment code. Then you can check to see which fragment is visible and do what you want accordingly.
This code is in my activity:
@Override
public void onBackPressed()
{
try
{
final LiveWorkFragment liveFragment = (LiveWorkFragment)getFragmentManager().findFragmentByTag("live_work");//LiveWorkFragment is a fragment
final NonLiveWorkFragment nonLiveFragment = (NonLiveWorkFragment)getFragmentManager().findFragmentByTag("non_live");//NonLiveWorkFragment is a fragment
final SignatureFragment signatureFragment = (SignatureFragment)getFragmentManager().findFragmentByTag("signature");//this is a Fragment too
if(liveFragment == null && nonLiveFragment == null && signatureFragment == null)
{
super.onBackPressed();
}
if(liveFragment != null)
{
if (liveFragment.isVisible())
{
//do what you want
}
}
}
}