Is account registration required
I am implementing MVP pattern in Android and I am using EventBus to find out what P resenter is from activity "A" that something happens on activity "B" to update views from "A".
I've registered the EventBus presenter inside the constructor, but I don't see any place where I could override it.
public class PresenterA extends nucleus.presenter.Presenter<ViewA> {
public PresenterA() {
EventBus.getDefault().register(this);
}
public void onEvent(ChangesEvent e) {
// change views
}
}
- Do I need to unregister at all when the presenter presumably resides until the app (it is not recreated when the configuration changes)?
- When the user leaves the application (closes activity "A") will the links be released or is it a memory leak?
+3
source to share
1 answer
- Deregistering is important, and when a user leaves the app it doesn't mean that resources are cleaned up instantly.
- Since the EventBus contains a static reference to the presenter, it is not released until the OS kills this process and is therefore considered a leak.
As for nucleus.presenter.Presenter
, it will be customary to register on onTakeView(ViewType view)
and unregister on onDropView()
as event handling changes the view
+1
source to share