From cf9e830cc7b0e587b37efd92d3b18161d6f558bf Mon Sep 17 00:00:00 2001 From: Tamim Hossain <132823494+CodeWithTamim@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:36:52 +0600 Subject: [PATCH] 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. --- V2rayNG/app/build.gradle.kts | 2 +- V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/V2rayNG/app/build.gradle.kts b/V2rayNG/app/build.gradle.kts index 79996d8c..e10a9976 100644 --- a/V2rayNG/app/build.gradle.kts +++ b/V2rayNG/app/build.gradle.kts @@ -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) } \ No newline at end of file diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt index d079eb2f..e865c31b 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt @@ -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)