Created
February 5, 2019 04:12
-
-
Save raghunandankavi2010/328e778e8909d1838e14f85a732a5ce7 to your computer and use it in GitHub Desktop.
Fragment back stack back press handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onBackPressed() { | |
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) { | |
mDrawerLayout.closeDrawers(); | |
} | |
else if (getSupportFragmentManager().getBackStackEntryCount() > 0) { | |
String fragmentTag = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName(); | |
if (fragmentTag.equals("dashboard")) { | |
//Toast.makeText(this.getApplicationContext(),""+fragmentTag,Toast.LENGTH_SHORT).show(); | |
finish(); | |
} else { | |
getSupportFragmentManager().popBackStack(); | |
} | |
} else { | |
super.onBackPressed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment