I want to pass the Model data into another activity using Parceler through Bundle intent. My problem is how could I pass the data from Presenter into the View layer to display in another activity using MVP architecture in android?
This is certainly possible. Presuming that your Activity implements your View interface you'd have a method in the interface like:
void startNextActivity(MyData data);
Then in the Activity:
@Override
void startNextActivity(MyData data) {
// create bundle
// send intent
}
And in Presenter:
view().startNextActivity(myData);
However I don't recommend that you do this
I'm of the opinion that quite a few classic Android patterns should be used sparingly when doing MVP. This includes things such as onActivityResult
& passing data around between Activities/Fragments using Bundle
.
To keep things as decoupled and clean as possible Activities should avoid talking to other Activities, Presenters shouldn't talk to other Presenters, etc. If you need to access data from one Activity in another Activity then send it to the model to be persisted. The next Activity will then be sent this data by its Presenter which will have got it from the model.
The following diagram gives a better overview:
Rather than passing the details as part of the Bundle when starting the next Activity they are persisted in the model for the next Activity to load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With