Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions on MVP Pattern for Android apps

I have been developing android apps for few years. Recently i have used MVP architecture in my app and after reading through a lot and making use of this Android10 github repo.

But there are few questions i have around this MVP architecture which i am looking for. Please help me to understand these better.

1) So i have three module app, domain, data. Which module presenters will go. In some app they have it in domain but i saw some other libraries have it in presentation or app module like this https://github.com/android10/Android-CleanArchitecture.

2 ) Can presenters have android related stuffs like Intents, Contexts, SharedPrefs ets? I don't think this should happen.

3) Can data module talk with app module and vice versa Or app module should talk to domain module which in term executes the things on data module

4 ) How can i do social login like Facebook with MVP architecture... any idea or link to explain? I have done that in a below way:

Activity: onFBButtonClick() --> presenter.onButtonClick() --> FacebookLoginManager.registerCallback

After this i directly get a callback on my activity on onActivityResult(int requestcode, int resultcode, Intent intent). Now according to fb sdk tutorial i have to call FbCallbackManager.onActivityResult(with all the params). But I can't pass these information in presenter as presenter should not know about intent(Platform Specific) thing. How can i now call FbcallbackManager.onActivity()?

like image 759
anshul Avatar asked Jan 13 '17 10:01

anshul


1 Answers

There are many approaches to implementation of MVP in Android.

Most of the approaches I've seen designate Activity/Fragment as MVP view. This seems natural initially, but too many issues and questions raises when you try to apply this scheme to a non-trivial applications.

After I investigated many MVP approaches (incl. the ones you linked), I came to a conclusion that neither Activity no Fragment should be MVC views.

The detailed reasoning behind this claim is summarized here: Why Activities are not UI Elements.

Following this line of sight, I proposed another implementation of MVP for android applications: MVP and MVC Architectures in Android.

As for your questions:

  1. Presenter is part of the "screen"
  2. Depends on which MVP approach you choose. I personally think that presenters are Activities and Fragments, therefore they can have dependencies on Android's components.
  3. I think that only the author of that git repo can answer this question.
  4. If you adopt the mindset of Activity/Fragment being presenters, you will immediately understand how to do it without polluting MVP views.

Also, as for FB integration, please see my answer here.

like image 190
Vasiliy Avatar answered Nov 11 '22 08:11

Vasiliy