MVP, set the view of the presenter to null on destroy?

I'll assume that you are using an Injection library (probably Dagger looking at your code) and the Presenter is annotated with @Singleton? If so, then setting to null is one option (and yes you should not be retaining an Activity instance on configuration changes).

Another option is to use a WeakReference in your Presenter that way setting to null is not required, although setting to null is more explicit.

You might consider using Interfaces with your Presenter rather than exposing the whole Activity to the Presenter instance - you may already be doign something like this, but not 100% clear from code provided.


I always did like that, I mean, I always set the view to null on the onDestroy() method. I try to use the LightCycle library to avoid having to code all that boilerplate code. Here's an article that explains Fernando Ceja's Clean Architecture. This is an MVP architecture widely used (I've worked in a couple of companies that use this pattern), there you can see that he also sets the view to null in the onDestroy() method. Let me know if I can help you any further.

UPDATE:

This answer is kinda outdated, now you can use the LifecycleOwner class from the Android's Jetpack tools. It's basically the same deal but with different API.


Could you not make the presenter lifecycle aware using https://developer.android.com/topic/libraries/architecture/lifecycle.html ? The presenter could then itself be responsible for setting the view to null when onDestroy() is called on the view.