Created
August 12, 2014 18:25
-
-
Save evant/6ccc8ae88dbe6e82d0c7 to your computer and use it in GitHub Desktop.
Delegate back button to child fragments.
This file contains 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
public interface OnBackPressed { | |
boolean onBackPressed(); | |
} | |
// ---------------------------------------------------------- | |
public class DelegateBackPressActivity extends Acitivity { | |
@Override | |
public void onBackPressed() { | |
for (Fragment f : getFragmentManager().getFragments()) { | |
if (f instanceof OnBackPressed && ((OnBackPressed) f).onBackPressed()) { | |
return; | |
} | |
} | |
super.onBackPressed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment