From 4b850af810a74b8fba1d184b3dd3767d01a8194f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 11 Sep 2022 11:36:16 +0100 Subject: [PATCH] fixing memory _leak_ on android Q when exiting screens --- .../src/main/kotlin/app/dapk/st/core/DapkActivity.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/domains/android/compose-core/src/main/kotlin/app/dapk/st/core/DapkActivity.kt b/domains/android/compose-core/src/main/kotlin/app/dapk/st/core/DapkActivity.kt index 59cec14..29ee41b 100644 --- a/domains/android/compose-core/src/main/kotlin/app/dapk/st/core/DapkActivity.kt +++ b/domains/android/compose-core/src/main/kotlin/app/dapk/st/core/DapkActivity.kt @@ -1,5 +1,6 @@ package app.dapk.st.core +import android.os.Build import android.os.Bundle import android.view.WindowManager import androidx.activity.ComponentActivity @@ -20,10 +21,13 @@ abstract class DapkActivity : ComponentActivity(), EffectScope { private lateinit var themeConfig: ThemeConfig + private val needsBackLeakWorkaround = Build.VERSION.SDK_INT == Build.VERSION_CODES.Q + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) this.themeConfig = ThemeConfig(themeStore.isMaterialYouEnabled()) + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } @@ -53,4 +57,11 @@ abstract class DapkActivity : ComponentActivity(), EffectScope { } } } + + override fun onBackPressed() { + if (needsBackLeakWorkaround && !onBackPressedDispatcher.hasEnabledCallbacks()) { + finishAfterTransition() + } else + super.onBackPressed() + } }