반응형
// Property that stores the button press time
var initTime = 0L
// Back button event handler
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
// Processing when the back button is pressed
if (keyCode === KeyEvent.KEYCODE_BACK) {
// Handles when the back button is pressed for the first time or when 3 seconds have passed since the back button was pressed
if (System.currentTimeMillis() - initTime > 3000) {
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show()
initTime = System.currentTimeMillis()
return true
}
}
return super.onKeyDown(keyCode, event)
}반응형
'💻 개발(Dev) > Android' 카테고리의 다른 글
| [Android][kotlin] Jetpack Compose 기본 설정 (+ render problem 해결방법) (0) | 2024.06.16 |
|---|---|
| [Android][Kotlin] 널(null) 안전성 / 엘비스 연산자(Elvis Operation ?:) / 예외(!!) (0) | 2024.05.15 |
| [Android] 안드로이드 스튜디오 이전 버전 설치 (0) | 2024.03.20 |
| [Android] Gradle version update 방법 (0) | 2024.03.20 |
| [Android] 텍스트 하이퍼링크 적용방법 (with strings.xml) (0) | 2024.03.13 |