Skip to content

Commit

Permalink
fix: loggers getting created more than once if activity is recreated
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian04 committed Jul 2, 2024
1 parent 66db628 commit 8329000
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name=".MyApplication"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/Theme.USBHIDClient"
Expand Down
23 changes: 16 additions & 7 deletions app/src/main/java/me/arianb/usb_hid_client/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.arianb.usb_hid_client

import android.app.Application
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand All @@ -18,6 +19,21 @@ import me.arianb.usb_hid_client.troubleshooting.ProductionTree
import me.arianb.usb_hid_client.ui.standalone_screens.OnboardingScreen
import timber.log.Timber

// Overriding Application so that the loggers only get created once, regardless of Activity lifecycle
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Shell.enableVerboseLogging = true
}

Timber.plant(ProductionTree())
}
}


// TODO: move all misc strings used in snackbars and alerts throughout the app into strings.xml for translation purposes.

// Notes on terminology:
Expand All @@ -28,13 +44,6 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Shell.enableVerboseLogging = true
}

Timber.plant(ProductionTree())

setContent {
Entrypoint()
}
Expand Down

0 comments on commit 8329000

Please sign in to comment.