Skip to content
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

NPE in fragment inject #124

Open
Cook1 opened this issue Mar 12, 2016 · 4 comments
Open

NPE in fragment inject #124

Cook1 opened this issue Mar 12, 2016 · 4 comments

Comments

@Cook1
Copy link

Cook1 commented Mar 12, 2016

The problem is when the application stays in the backgound for a while and a recently displayed activity is recycled by Android. Bringing back the application causes NPE as the activity's component is called by the fragment before it is initialized. In my case it often happens after pushing on notification which starts new activity. This issue is very hard to reproduce. By the way this issue occurs only on my device with android 5.

@FizzyMobile
Copy link

3e2e382#commitcomment-16642857

To reproduce: switch ON Don't keep activities under Apps in Settings/Developer options. This will destory every activity as soon as the user leaves it.

@Cook1
Copy link
Author

Cook1 commented Mar 26, 2016

Well, I suppose i fixed this issue. The reason is that the code which create fragment component in activity doesn't executed. Most of the time it works well, but when activity goes to background and is called after some time, FragmentController tries to restore fragment (in onCreate() callback in FragmentActivity.class), that's why dependencies's injections in fragment happen before fragment component initialization in activity. That's why NPE occures.
So to fix this behaviour i put fragment component initialization before super.onCreate() in my activity and the issue is gone.

@Rainer-Lang
Copy link

Could this be provided as PR here?

@FizzyMobile
Copy link

You may find this interesting: Efficient and bug-free fragment injection in Android MVP applications on medium.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants