kotlin – Android Application class is never called-ThrowExceptions

Exception or error:

I have a custom application class in my app that should initialize the DI framework Toothpick in its OnCreate() method. But the method does not get called.

Here is my application class:

package dev.lukger.luketimer.presentation.helpers

import android.app.Application
import dev.lukger.luketimer.data.interfaces.ITimerRepository
import dev.lukger.luketimer.data.interfaces.IUserRepository
import dev.lukger.luketimer.data.repositories.TimerRepoImpl
import dev.lukger.luketimer.data.repositories.UserRepoImpl
import toothpick.ktp.KTP
import toothpick.ktp.binding.bind
import toothpick.ktp.binding.module

class LukeTimerApplication : Application() {

    private val timerModule = module {
        bind<ITimerRepository>().toClass<TimerRepoImpl>().singleton()
        bind<IUserRepository>().toClass<UserRepoImpl>().singleton()
    }

    override fun onCreate() {
        super.onCreate()

        KTP.openRootScope().installModules(timerModule)
    }
}

And here is the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="dev.lukger.luketimer">

    <application
        android:name=".presentation.helpers.LukeTimerApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
        <activity android:name=".presentation.OnboardingActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

As you can see the application class is referenced in the manifest but Android Studio throws a warning stating “Class LukeTimerApplication is never used”.
How can this be?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *