Android MVP - Should Activity be View or Presenter?

I want to implement my next application with an MVP template, so I started reading some articles on how it should be implemented. The main problem for me is that there are different approaches to this scheme. Some people say that we should consider the activity as a point of view, but some others that the activity should be leading.

Activity as a view is described here: Android MVP and that makes sense. But on the other hand, I found this answer with a few upvotes https://stackoverflow.com/a/1671919/129 , and someone says that activity should be a presenter.

Does anyone have experience with this template?

+7
android design-patterns mvp
source share
6 answers

After a moment, I thought that activity should be seen as a representation. If we separate business logic from activity, then it will be easy to replace activity with a fragment or view. We can even use our models and presenters and use them in a desktop application, simply adding new views to them. It is also better to check the purpose of creating the presenter as a regular object, rather than activity.

+8
source share

Activity is very close to your location, so this should be an idea. And your business logic should be in the Presenter created by your activity. To learn more about MVP, check out MVP for Android.

enter image description here

+7
source share

I consider it safe to consider Activity as a Leader. A view can be thought of as an XML layout file. A host is something that has a direct connection with the Model, as well as View (s), as stated in the answer that you indicated above. In Activity, you connect to View (s) and remain as an intermediary between views and model (s), which is actually the functionality of Presenter. It takes input events from the view (s) and sets the values ​​(s) received from the Model (s) to display in the view (s).

+2
source share

Take a look at the G + Android MVP community and specifically for the sample https://github.com/spengilley/ActivityFragmentMVP

This is an implementation of a passive view, best suited for use in tests.

+1
source share

Actions must be views as they appear in graphical environments. Presenters and models can be written in pure Java and easily tested.

See this AndroidMvc / Mvp platform

https://github.com/kejunxia/AndroidMvc

Also check out the MVP sample here https://github.com/kejunxia/AndroidMvc/tree/master/samples/simple-mvp

0
source share

The term View is overloaded here; the view of Android is different from the view that is supposed to be used in the MVP template. View is an interface that must be implemented either by Activity / Fragment. You can see the official examples of Android MVP .

I suggest starting it from the main one . Here is the stream from the page.

enter image description here

0
source share

All Articles