Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVP - should an Activity be a View or Presenter?

I want to implement my next application with MVP pattern, so I started of reading some articles about how it should be implemented. The main problem for me is that there are different approaches to this pattern. Some people say that we should treat activity as a view but some others that activity should be a presenter.

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

Does anyone has an experience with this pattern?

like image 837
Greg Avatar asked Jul 24 '14 09:07

Greg


2 Answers

After a moment's thought I think Activity should be considered as a View. If we separate business logic from activity then it will be easy to replace activity with a fragment or a view. We even will be able to take our models and presenters and use them in desktop application, just adding new views to them. It is also better for testing purpose to create presenter as an normal object, not activity.

like image 84
Greg Avatar answered Oct 20 '22 00:10

Greg


Activity is very close to your layout so it should be a view. And your business logic should be in the Presenter created by your Activity. To understand more about MVP take a look at - MVP for android

enter image description here

like image 26
Ajit Singh Avatar answered Oct 20 '22 01:10

Ajit Singh