Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devrath/e88cc70df57b498e58cc to your computer and use it in GitHub Desktop.
Save devrath/e88cc70df57b498e58cc to your computer and use it in GitHub Desktop.
This is used to check onBackpressed if only one fragment is found using backstack count
Checking the backstack works perfectly
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (getFragmentManager().getBackStackEntryCount() == 1)
{
// DO something here since there is only one fragment left
// Popping a dialog asking to quit the application
return false;
}
}
return super.onKeyDown(keyCode, event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment