Notice
Recent Posts
Recent Comments
Link
투케이2K
723. (Android/Java) [Android Sdk 33] 뒤로 가기 onBackPressed deprecated 대응 getOnBackPressedDispatcher 등록 본문
Android
723. (Android/Java) [Android Sdk 33] 뒤로 가기 onBackPressed deprecated 대응 getOnBackPressedDispatcher 등록
투케이2K 2024. 1. 17. 20:22[개발 환경 설정]
개발 툴 : AndroidStudio
[소스 코드]
// -----------------------------------------------------------------------------------------
// TODO [액티비티 onCreate]
// -----------------------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a_intro);
// ===============================
// [Android Sdk 33] : [Activity] : onBackPressed : deprecated 대응
// ===============================
try {
// [callBack 등록]
getOnBackPressedDispatcher().addCallback(this, callback);
}
catch (Exception e){
e.printStackTrace();
}
} // TODO [메인 종료]
// -----------------------------------------------------------------------------------------
// [OnBackPressedCallback 이벤트 정의]
// -----------------------------------------------------------------------------------------
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
S_Log._E_("[handleOnBackPressed] : 뒤로가기 수행", null);
}
};
[결과 출력]
E///===========//: ================================================
I/: [LOG :: CLASS PLACE :: com.example.javaproject.A_Intro$2.handleOnBackPressed]
I/: ----------------------------------------------------
I/: [LOG :: NOW TIME :: 2024-01-17 13:02:56 수요일]
I/: ----------------------------------------------------
I/: [LOG :: DESCRIPTION :: [handleOnBackPressed] : 뒤로가기 수행]
E///===========//: ================================================
반응형
'Android' 카테고리의 다른 글
Comments