Skip to content

Instantly share code, notes, and snippets.

@PepDevils
Last active February 20, 2017 17:32
Show Gist options
  • Save PepDevils/f96e1bf1d77e7566c6d2cb372d1499d9 to your computer and use it in GitHub Desktop.
Save PepDevils/f96e1bf1d77e7566c6d2cb372d1499d9 to your computer and use it in GitHub Desktop.
Close all Fragments before the activity in onBackPressed button..
@Override
public void onBackPressed() {
List<Fragment> all_frags = getSupportFragmentManager().getFragments();
if(all_frags != null){
if (all_frags.size() == 0) {
super.onBackPressed();
} else {
for (Fragment frag : all_frags) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
}
}
}else{
super.onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment