I have upgraded targetSdkVersion
and compileSdkVersion
to 33
.
I am now getting a warning telling me that onBackPressed is deprecated.
I see suggestions to use android.window.OnBackInvokedCallback or androidx.activity.OnBackPressedCallback to handle back navigation instead. Can anyone can help me use the updated method?
Example
Use Case
I use if (isTaskRoot) {}
inside the onBackPressed() method to check whether the activity is the last one on the activity stack.
override fun onBackPressed() {
if (isTaskRoot) { // Check whether this activity is last on the activity stack. (Check whether this activity opened from a Push Notification.)
startActivity(Intent(mContext, Dashboard::class.java))
finish()
} else {
finishWithResultOK()
}
}