Notice
Recent Posts
Recent Comments
Link
투케이2K
453. (kotlin/코틀린) [Android Sdk 33] 뒤로 가기 onBackPressed deprecated 대응 getOnBackPressedDispatcher 등록 본문
Kotlin
453. (kotlin/코틀린) [Android Sdk 33] 뒤로 가기 onBackPressed deprecated 대응 getOnBackPressedDispatcher 등록
투케이2K 2024. 1. 17. 20:26[개발 환경 설정]
개발 툴 : AndroidStudio
개발 언어 : Kotlin
[소스 코드]
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onCreate]
// -----------------------------------------------------------------------------------------
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_a_intro)
// ===============================
// [Android Sdk 33] : [Activity] : onBackPressed : deprecated 대응
// ===============================
try {
// [callBack 등록]
onBackPressedDispatcher.addCallback(this, callback)
}
catch (e : Exception) {
S_Log._printStackTrace_(A_Intro@this, "예외 상황 발생", null, e)
}
} // TODO [메인 종료]
// -----------------------------------------------------------------------------------------
// [OnBackPressedCallback 이벤트 정의]
// -----------------------------------------------------------------------------------------
val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
S_Log._E_("[handleOnBackPressed] : 뒤로가기 수행", null)
}
}
[결과 출력]
E///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.kotlinproject.A_Intro$2.handleOnBackPressed]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2024-01-17 13:02:56 수요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: [handleOnBackPressed] : 뒤로가기 수행]
E///===========//: ================================================
반응형
'Kotlin' 카테고리의 다른 글
Comments