Who calls db requests and gets http in mvp android

I need to write an Android application that takes a date from the internet and a database and loads the activity. I am planning to use the mvp design pattern. l. The activity will load the controls on the screen. 2. On the chick button, the action will call the presenter method to get mo data from the internet.

Q1: I doubt who will call the method select method DB or HTTGet. Model on a presenter?

Q2: Asynctask will do an HTTP receive. This is present in the helper class. But who is calling asynctask.execute. Host or Model?

The http response is xml. This is available in the asynctask do In the background () method.

Asynctask will call another helper to parse the XML and get all the strings. Q3 Will the helper name the given model methods? Q4 Who will now tell the set activity method to refresh the view?

+3


source to share


1 answer


Q1 - It is good practice to encapsulate the select method and HTTP request inside the repository (model layer)

Q2 - AsynkTask is an old approach, it has some disadvantages, maybe should use RxJava?

Q3 - The transformation of the raw response to the data object must be done inside the repository. This data object then goes to the listener for that network request, in your case the listener is the presenter.



Q4 - When the presenter receives a data object, it notifies that the data has changed.

PS You can see this library https://github.com/MaksTuev/ferro , it introduces a new way to manage background task.

+2


source







All Articles