Replace deprecated onBackPressed with onBackPressedDispatcher (#3389)

Replaced deprecated `onBackPressed` with `onBackPressedDispatcher`. The `onBackPressedDispatcher` handles the home button press by delegating to the appropriate back navigation method.
This commit is contained in:
Tamim Hossain authored and GitHub committed 2024-07-31 20:36:52 +08:00
1 parent 804e425a87
commit cf9e830cc7
2 files changed
+4 -2

No files matched your search

+1 -1
View File
@@ -133,7 +133,7 @@ dependencies {
implementation(libs.language.json)
implementation(libs.quickie.bundled)
implementation(libs.core)
// Updating these 2 dependencies may cause some errors. Be careful.
implementation(libs.work.runtime.ktx)
implementation(libs.work.multiprocess)
}
@@ -23,7 +23,9 @@ abstract class BaseActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> {
onBackPressed()
// Handles the home button press by delegating to the onBackPressedDispatcher.
// This ensures consistent back navigation behavior.
onBackPressedDispatcher.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)