Skip to content

Instantly share code, notes, and snippets.

@danielwilson1702
Last active September 5, 2015 12:10
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 danielwilson1702/4e4e4aee1c80dea5d817 to your computer and use it in GitHub Desktop.
Save danielwilson1702/4e4e4aee1c80dea5d817 to your computer and use it in GitHub Desktop.
Activity hosting fragments with back button listeners
@Override
public void onBackPressed() {
tellFragments();
super.onBackPressed();
}
private void tellFragments(){
List<Fragment> fragments = getSupportFragmentManager().getFragments();
for(Fragment f : fragments){
if(f != null && f instanceof BaseFragment)
((BaseFragment)f).onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment