Open Cooki1e opened 8 years ago
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.
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.
Could this be provided as PR here?
You may find this interesting: Efficient and bug-free fragment injection in Android MVP applications on medium.com
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.