Mosby 3.1.0 NPEs in Activity#onDestroy()
See original GitHub issueAfter upgrading app to Mosby 3.1.0 crash analytics have started displaying crashes like:
java.lang.RuntimeException: Unable to destroy activity {p/p.a}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvp.MvpPresenter.detachView()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4299)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4317)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1569)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6274)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.hannesdorfmann.mosby3.mvp.MvpPresenter.detachView()' on a null object reference
at com.hannesdorfmann.mosby3.mvp.delegate.ViewGroupMvpDelegateImpl.detachPresenterIfNotDoneYet(ViewGroupMvpDelegateImpl.java:301)
at com.hannesdorfmann.mosby3.mvp.delegate.ViewGroupMvpDelegateImpl.onActivityDestroyed(ViewGroupMvpDelegateImpl.java:255)
at android.app.Application.dispatchActivityDestroyed(Application.java:253)
at android.app.Activity.onDestroy(Activity.java:1851)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:358)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
at p.a.onDestroy(a.java:)
at android.app.Activity.performDestroy(Activity.java:6922)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1154)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4286)
... 9 more
Do not have the specific repro steps available yet, but reading the source in ViewGroupMvpDelegateImpl
:
private void destroyPresenterIfnotDoneYet() {
if (!presenterDestroeyed) {
P presenter = delegateCallback.getPresenter();
presenter.destroy();
To me this looks like the code is assuming too much about the fragment/activity lifecycle - the fragment lifecycle has not reached MvpFragment#onCreate()
where the presenter is created but the the activity gets destroyed for some other reason, and presenterDestroeyed
defaults to false
.
For what it’s worth, there’s also a typo in presenterDestroeyed
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Activity - Android Developers
The entire lifetime of an activity happens between the first call to onCreate(Bundle) through to a single final call to onDestroy() . An...
Read more >Ted Mosby - Software Architect - Hannes Dorfmann
Activity and Fragment seems to be both, because they have lifecycle callbacks like onCreate() or onDestroy() as well as responsibilities of ...
Read more >How to update status in remote database if the activity's ...
... guarantee a method run no earlier than the activity's onDestroy() callback, an attractive solution is Android Jetpack's WorkManager for.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Working on it, along migrating to android x
I don’t know actually. Stacktrace do not include either: