V
- Generic type of view that the presenter interacts with. To make presenter
testable, the view should be implemented with an interface and presenter refers to it instead of the view implementation.
This will allow to write unit tests without any android SDK dependency.public interface Presenter<V>
The Presenter
is responsible for orchestrating all the application's use cases,
So it acts as a middle man that retrieves model from data-layer and shows it in the view.
In MVP pattern, view is made completely passive and is no longer responsible for updating itself from the model. So it routes all user actions to the presenter and the presenter decides the action to take.
Modifier and Type | Method and Description |
---|---|
V |
getView() |
boolean |
isViewAttached() |
void |
onDestroyed()
Called when a user leaves the view completely.
|
void |
onViewAttached(V view)
Called when the view attached to the screen.
|
void |
onViewDetached()
Called when the view detached from the screen.
|
void onViewAttached(V view)
This method will be invoked during Activity.onStart()
, Fragment.onResume()
and View.onAttachedToWindow()
.
view
- the view that the presenter interacts withvoid onViewDetached()
This method will be invoked during Activity.onStop()
, Fragment.onPause()
and View.onDetachedFromWindow()
.
void onDestroyed()
Note that on configuration changes like rotation, presenter instance will be alive.
boolean isViewAttached()
@Nullable V getView()