Search code examples
androidarchitecturemvpandroid-contextandroid-moxy

How to get context in moxy presenter android


How do I can get activity context from Moxy presenter? At first sight it's very easy...: 1. Add Context getMvpActivity (); into MvpView interface and implement it in Acivity. 2. And in a presenter call getViewState().getMvpActivity().

But Moxy don't allow to add the non-void methods to MvpView interface. Pls help me.

P.S. I need context in the Presenter to init App Component(activity is a param for static getter).

Thanks. Sorry for some grammar mistakes.


Solution

  • Right solution is not using activity context in the presenter. Because, in case of activity recreation, this context will leak (because presenter will be still alive). You able to use application context. You can pass it through presenter's constructor.