-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[todo-mvp-dagger] Fragments get constructed twice every time an Activity is restored #495
Comments
@google: If you at Google are not able to properly inject things with Dagger than something goes really wrong with this DI-Tool. |
I think the main problem is with the sample assuming that you can even As it stands, the todo-mvp-dagger sample is likely to give wrong information to people who are trying to learn how to work with dagger, which is pretty bad for a pseudo-"official" repository. I guess a more general issue is also the fact that Dagger even lets you do this. Dagger2 is supposed to be all about compile-time safety and checks, but dagger-android mostly fails at runtime whenever you screw something up - but that's a problem with Dagger, not this repository. |
Thanks for caching it! This was a bug I introduced due to me trying to make everything a nail when dagger was a hammer. I'll refactor shortly. FYI, this project is maintained both by Google dev advocates & members of the community. Your constructive feedback is always appreciated and will be taken into account. |
hi @peterholak would you like to take a stab at fixing the fragment injection issue? I see 2 solutions that would work:
Since you found the issue I figured I'd give you a chance to get some internet points :-) If not I'd be happy to fix. Thank you and enjoy your day |
Thanks, but I'm a bit busy right now to take a look at this. I would probably lean more towards the second option (any |
The code currently
@Inject
s theStatisticsFragment
inStatisticsActivity
, which can lead to a very confusing situation when the Activity is restored (configuration change, low memory, etc.):StatisticsFragment
instance and injects it into the field.StatisticsFragment
instance gets created and attached bysuper.onCreate
as part of the restore process.fragment
instance.fragment
field now contains an unused, unattached fragment.The fact that
StatisticsFragment
's constructor was called twice is also a problem.A similar situation can occur with the other activities.
The text was updated successfully, but these errors were encountered: