Pass bundle intent in android using MVP

坚强是说给别人听的谎言 提交于 2019-12-04 07:24:37

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!