How about activity's retained scope with dagger.android ?
See original GitHub issueIn Android, an activity is destroyed and recreated on every configuration change. One common pattern to hold certain injected fields over this process is to instantiate a component inside the activity the first time it gets created and then to use Activity#onRetainNonConfigurationInstance to return a dagger component that would be accessible on the same newly created activity. By doing so, the component’s lifecycle is now bound to the activity’s real lifecycle, i.e. ignoring configuration changes.
I feel the two problems dagger.android
was meant to address―boilerplate code and “a class shouldn’t know anything about how it is injected”―also apply to this pattern.
I don’t know if this question has already been taken into consideration. This is, in my case, a showstopper when I considered using the new AndroidInjector
. I also don’t have any proposition for good APIs but I thought it would be worth looking into it.
Is it something we could expect from the future releases?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top GitHub Comments
I guess the recently announced Android Architecture Components is the right solution.
Ron, thanks for the tip, I will have a look at it then.
Although I did not benchmark it because my goal is not here to save time. I don’t think it Is the goal of the
AndroidInjector
either, is it? I just want to hold needed data for an activity’s functional lifecycle for the shortest period of time.