fixing memory _leak_ on android Q when exiting screens

This commit is contained in:
Adam Brown 2022-09-11 11:36:16 +01:00 committed by Adam Brown
parent ee91de4301
commit 4b850af810
1 changed files with 11 additions and 0 deletions

View File

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