Transfer package to android using MVP

I want to transfer model data to another action using Parceler through the Bundle intent. My problem is how to transfer data from Presenter to the View layer for display in another event using the MVP architecture in android?

+4
source share
1 answer

It is certainly possible. Assuming your activity implements the View interface, you will have a method in the interface, for example:

void startNextActivity(MyData data); 

Then in the Office:

 @Override void startNextActivity(MyData data) { // create bundle // send intent } 

And in the presenter:

 view().startNextActivity(myData); 

However, I do not recommend you do this.

I believe that when creating MVP it is rather rare to use several classic Android models. This includes things like onActivityResult and passing data between actions / fragments using the Bundle .

In order for everything to be as free and clean as possible, actions should avoid communicating with other actions, speakers should not talk to other speakers, etc. If you need to access data from one action in another event, send it to the saved model. Then the next event will be sent by this data to its presenter, who will receive it from the model.

The following diagram gives a better overview:

MVP chart

Instead of passing the details as part of the package when the next action starts, they are saved in the model to load the next action.

+10
source

Source: https://habr.com/ru/post/1265735/


All Articles