Skip to content Skip to sidebar Skip to footer

Timber Duplicate Logs After Calling Finish() And Restarting App

I have an onTouchListener on my TextView. On touch, I log with Timber.i() and then I call finish(). If after finish(), I launch my app again, and click again on the TextView, It wi

Solution 1:

The problem is that you are 'planting' trees in the Activities onCreate method. Instead, use a custom Applications subclass and plant the trees there.


class MyApp : Application() {

    override fun onCreate() {
        super.onCreate()

        if (BuildConfig.DEBUG) {
             Timber.plant(DebugTree())
        }
    }
}

And update your AndroidManifest accordingly:

<application android:name="com.foo.MyApp" android:icon="@mipmap/ic_launcher" android:label="@string/app_name"/>


Solution 2:

I surely am very late but still posting it. @cwbowron has explained it very well.
This trick got it fixed for me:

class TimberLogImplementation {
companion object {
    fun initLogging() {
        if(Timber.treeCount() != 0) return
        if (BuildConfig.DEBUG) Timber.plant(DebugTree())
        else Timber.plant(ReleaseTree())
        }
    }
}

Post a Comment for "Timber Duplicate Logs After Calling Finish() And Restarting App"