Created
September 24, 2019 15:46
-
-
Save Slowhand0309/bf03f43fe816c950b6d322b5a2496436 to your computer and use it in GitHub Desktop.
[Backボタン制御] #Android
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
// legacy | |
public boolean onKeyDown(int keyCode, KeyEvent event) { | |
if (keyCode == KeyEvent.KEYCODE_BACK){ | |
// do something... | |
} else { | |
return super.onKeyDown(keyCode, event); | |
} | |
} |
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
// use onBackPressedDispatcher | |
activity.onBackPressedDispatcher.addCallback(this@MainFragment) { | |
// do something... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment