標準の戻るボタンが押されたときにandroidのホーム画面に遷移
サンプルコード
back_to_home
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return if (keyCode == KeyEvent.KEYCODE_BACK) {
val homeIntent = Intent(Intent.ACTION_MAIN)
homeIntent.addCategory(CATEGORY_HOME)
homeIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
this@自分のクラスの名前.startActivity(homeIntent)
super.onKeyDown(keyCode, event)
} else {
super.onKeyDown(keyCode, event)
}
}
この関数を使いたいクラスに入れることで、戻るボタンが押された時の動作を変えることができます。
自分のクラスの名前のところを変更して使用してください