안드로이드에서 뒤로가기 버튼을 두번 눌렀을 때 종료하는 방법입니다.

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
private var doubleBackToExitPressedOnce = false | |
override fun onBackPressed() { | |
if (doubleBackToExitPressedOnce) { | |
super.onBackPressed() | |
return | |
} | |
this.doubleBackToExitPressedOnce = true | |
Toast.makeText(this, "종료하실려면 한번 더 눌러주세요.", Toast.LENGTH_SHORT).show() | |
Handler().postDelayed(Runnable { doubleBackToExitPressedOnce = false }, 2000) | |
} |
'Android(Kotlin)' 카테고리의 다른 글
Android Notification (0) | 2021.01.21 |
---|---|
Android kotlin timeStamp (0) | 2021.01.18 |
android inapp review (0) | 2021.01.15 |
AAC(MVVM) - ViewModel (0) | 2021.01.13 |
databinding (0) | 2021.01.13 |