@Module
@InstallIn(SingletonComponent::class)
object AnalyticsModule {
@Provides
fun provideAnalyticsService(): AnalyticsService {
return AnalyticsServiceImpl()
}
}
@AndroidEntryPoint
class ExampleActivity: AppCompatActivity() {
@Inject lateinit var service: AnalyticsService
}
Since I wanted to use AnalyticsService anywhere in the app, I'm providing it in SingletonComponent/ ApplicationComponent.
- Does service object gets destroyed when Activity is destroyed?
- Or it will get garbage collected only when Application is destroyed?