-
Notifications
You must be signed in to change notification settings - Fork 207
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
Rare NPE if presenter used in onActivityResult #238
Comments
It seems that onActivityResult called before onCreate. But this shouldn't. Could you debug please, that onCreate called before onActivityResult or not? |
Okay. I'll add logs to the onCreate and onActivityResult of base fragment. |
It will be something like this. abstract class MirrorFragment : MvpAndroidXFragment(), OnBackPressedListener {
private var isOnCreateCalledBeforeSuper = false
private var isOnCreateCalledAfterSuper = false
override fun onCreate(savedInstanceState: Bundle?) {
isOnCreateCalledBeforeSuper = true
super.onCreate(savedInstanceState)
isOnCreateCalledAfterSuper = true
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (!isOnCreateCalledBeforeSuper || !isOnCreateCalledAfterSuper) {
Timber.e("onCreate is not called: %b, %b.", isOnCreateCalledBeforeSuper, isOnCreateCalledAfterSuper)
}
super.onActivityResult(requestCode, resultCode, data)
}
} |
This code was in production for a while and i never had logs in Crashlytics about "onCreate is not called". So at least in this case onCreate is seems to be called. I could check other things if you have any ideas. |
This is pretty rare crash and i could not reproduce it on my devices.
Crashlytics reports — http://crashes.to/s/4a9639b6eba, http://crashes.to/s/a2bb8339d24
Crashlytics report sample — com.mirrorai.app_issue_1947_crash_5C115CBA03CC000111718A8B503A537C_DNE_0_v2.txt
I have several fragments that receives results via onActivityResult. Let's take photo gallery for example:
and a bit later in this class
presenter in uploadPhotoFromGallery sometimes (rarely but noticeable) is null and causes NPE.
I use custom base fragment MvpAndroidXFragment that is just Kotlin clone of MvpAppCompatFragment for AndroidX — https://gist.github.com/asfdfdfd/87552746c9182f6b7311f3d9ce6272a6.
But this issue has appeared before migrating to Android X.
The text was updated successfully, but these errors were encountered: