question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When to destroy activity's presenter

See original GitHub issue

We need a more reliable way to detect when to destroy activity’s presenter.

Here is where the issue that started the discussion: https://github.com/konmik/nucleus/issues/42#issuecomment-204233175

TL/DR: activity’s finish() can be called some time after onPause, so this code will leak the activity’s presenter: https://github.com/konmik/nucleus/blob/master/nucleus/src/main/java/nucleus/view/NucleusActivity.java#L76

Possible solutions:

a) Leverage retained fragments. This will solve the presenter destruction issue but we will leak background tasks sometimes.

b) Extend PresenterLifecycleDelegate lifecycle to explicitly call onDestroy.

c) Install system-wide lifecycle listener registerActivityLifecycleCallbacks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:51 (27 by maintainers)

github_iconTop GitHub Comments

1reaction
konmikcommented, Apr 22, 2016

3.0.0-beta is on maven

1reaction
bejibxcommented, Apr 15, 2016

Hey, can we use isChangingConfigurations() instead of isFinishing()? So presenter will NOT be destroyed only if it is configuration change incoming.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MVP: Don't keep activities.Is presenter alive? - Stack Overflow
Yes. When your activity is destroyed, all the objects in that activity will also be destroyed. You can recover the state of some...
Read more >
Android MVP: Keeping Presenters Alive | craigrussell
When the View is being destroyed, we inform the Presenter so that it doesn't try to update an invalid View. The rest of...
Read more >
The activity lifecycle - Android Developers
When your activity is destroyed because the user presses Back or the activity finishes itself, both the system's and the user's concept of...
Read more >
Model-View-Presenter: Android guidelines - Medium
The presenter doesn't make sense without a view. It comes with the view and goes when the view is destroyed. It manages one...
Read more >
MVP for Android: how to organize the presentation layer
The presenter is defined as a property for the activity, and when the button is clicked, it calls validateCredentials() , which will notify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found