Explanation of @PerActivity
This is not really an issue, as much as a question: How is the @PerActivity scope enforced?
I can never seem to find how exactly scopes work in Dagger 2. Could you may be eleborate more on that? (or provide a link where it is explained?)
http://fernandocejas.com/2015/04/11/tasting-dagger-2-on-android/
So if I'm understanding it right, the @PerActivity will work exactly the same as @Singleton if we never recreate the ActivityModule?
It would be nice to try that by the way...
This is actually one of my concerns with "Scoped" components in Dagger 2. The PerActivity, PerFragment or other annotations are leading you to think that Dagger will magically manage the scope of those components for you, but it doesn't.
So correct me if I'm wrong, but unless you destroy your component in Activity.onDestroy() (which might not get called anyway http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29), the component will not be garbage collected, and you will leak everything that's inside of it (probably your Activity).
And then, how does this even work if your Activity or Fragment is started twice? They will share the same component (the first one that was created). Which means that if you are using that component to provide an Activity instance to your fragments, this might return another Activity than the one your fragment is attached to.
That is very scary to me and I wouldn't use custom scopes for that reason unless I knew exactly what I was doing...
@nbarraille onDestroy is not guaranteed to be called only in the case the host process is being killed outright. Therefore, you won't leak anything - the hosting process dies along with all its ClassLoaders/statics, and there's nothing to leak.
If the Activity is started twice in the same process, onDestroy will be called.
@cmc5788 :+1:
If the Activity is started twice in the same process, onDestroy will be called.
Wait, what? No, this is not true, in general you can start one Activity as many times you want.