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
2024-07-31 18:36:52 +06:00
committed by GitHub
parent 804e425a87
commit cf9e830cc7
2 changed files with 4 additions and 2 deletions

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)
}

View File

@@ -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)