I have an app with three activities.
Launch Activity A -> Activity B -> Activity -> C
Previous activity is finished while navigating to next activity.
I am injecting objects in Activity A and Activity B in the following way
@Module
@InstallIn(SingletonComponent::class)
class MyProvider {
// Provides object in Activity A
@Provides
fun provideTheObjectA(): SomeObjectA {
return SomeObjectA()
}
}
@Module
@InstallIn(ActivityComponent::class)
class AvtivtyBProvider {
// Provides object in Activity B
@Provides
fun provideTheObjectB(): SomeObjectB {
return SomeObjectB()
}
}
class ActivtyA: AppCompatActivity(){
@Inject
SomeObjectA
}
class ActivtyB: AppCompatActivity(){
@Inject
SomeObjectB
}
I want to understand the difference between SingletonComponent and ActivityComponent here.
So,
- when activity A is destroyed, will the object A also be destroyed? (Its generated under SingletonComponent scope) (Note: I am not using the @Singleton annotation
) I believe it will be destroyed/garbage collected. Am I right here? - If I had provided the @Singleton annotation, I assume Object A will not be destroyed/garbage collected even though activity A is destroyed. Am I right here?
If so What is the point of @SingletonComponent if I have not used @Singleton annotation?
- I assume that when Activity B is destroyed, object B will also be destroyed/garbage collected. Am I right here?