Saturday, July 3, 2021

【ANDROID STUDIO】The Application Class With Dagger

 package com.example.dagger


import android.app.Application
class SmartPhoneApplication : Application() {
lateinit var smartPhoneComponent: SmartPhoneComponent
override
fun onCreate() {
smartPhoneComponent = initDagger()
super.onCreate()
}

private fun initDagger(): SmartPhoneComponent =
DaggerSmartPhoneComponent.builder()
.memoryCardModule(MemoryCardModule(1000))
.build()
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dagger">

<application
android:name=".SmartPhoneApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

package com.example.dagger

import dagger.Component

@Component(modules = [MemoryCardModule::class, NCBatteryModule::class])
interface SmartPhoneComponent {
fun inject(mainActivity: MainActivity)
}

No comments:

Post a Comment

End of Summer Sale ☀️😎

20% OFF Inside!🤯 ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏...