Issue
Research: Couldn't find anything similar.
I have a Singleton
and I inject it into my SecondActivity
in the Constructor using InjectorUtil.inject(this);
. I then call mySingleton.getPersonCount()
and it gives me the count.
My problem is that when I leave the app and return to it. From my understanding causing the onStop()
then onStart()
. When it starts it instantly crashes and says that mySingleton.getPersonCount()
is null
.
So should I be calling InjectorUtil.inject(this);
in onStart()
too? or am I missing something?
Solution
I found fb-android-dagger to be useful when setting up dagger in my app. I inject my activities in onCreate
and have never had to worry about whether or not Android has destroyed them.
I would also refer to stopping and restarting an activity. Android calls onStart
both when it creates your activity and when it restarts the activity from the stopped state, so you do not want to inject there (unless you're re-creating something you released in onStop
)
Answered By - Alex Baker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.