fix(app): control LeakCanary lifecycle more explicitly

This commit is contained in:
Harsh Shandilya
2023-03-18 21:53:50 +05:30
parent 538f98b736
commit ddd958a8d6
2 changed files with 8 additions and 3 deletions

View File

@@ -46,15 +46,19 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
instance = this instance = this
LeakCanary.config = val eventListeners = LeakCanary.config.eventListeners + SentryLeakUploader
LeakCanary.config.copy(eventListeners = LeakCanary.config.eventListeners + SentryLeakUploader)
if ( if (
BuildConfig.ENABLE_DEBUG_FEATURES || BuildConfig.ENABLE_DEBUG_FEATURES ||
prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false) prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false)
) { ) {
LogcatLogger.install(AndroidLogcatLogger(DEBUG)) LogcatLogger.install(AndroidLogcatLogger(DEBUG))
AppWatcher.manualInstall(this)
setVmPolicy() setVmPolicy()
LeakCanary.config.copy(dumpHeap = true, eventListeners = eventListeners)
LeakCanary.showLeakDisplayActivityLauncherIcon(true)
AppWatcher.manualInstall(this)
} else {
LeakCanary.config.copy(dumpHeap = false, eventListeners = eventListeners)
LeakCanary.showLeakDisplayActivityLauncherIcon(false)
} }
prefs.registerOnSharedPreferenceChangeListener(this) prefs.registerOnSharedPreferenceChangeListener(this)
setNightMode() setNightMode()

View File

@@ -5,5 +5,6 @@
<resources> <resources>
<bool name="leak_canary_allow_in_non_debuggable_build">true</bool> <bool name="leak_canary_allow_in_non_debuggable_build">true</bool>
<bool name="leak_canary_watcher_auto_install">false</bool>
<bool name="light_status_bar">true</bool> <bool name="light_status_bar">true</bool>
</resources> </resources>