将数据从视图传递到Android MVP中的另一个模型视图

时间:2018-09-18 18:44:37

标签: android kotlin mvp

在我的MVP应用中,我有两个活动(视图)。第一个从用户那里获取输入数据,这将需要第二个活动的模型来从仓库中获取数据。

目前,我有以下链接:

VIEW 1 中的

数据- VIEW 2 => PRESENTER 2 = > 模型2

我想知道是获得相同结果的另一种或更清洁的方法。数据是可选的-因此它不一定总是通过。

1 个答案:

答案 0 :(得分:0)

This is one of the unfortunate disadvantages on Android - due to the way Activities and Co. work, it is not possible to seperate the View from logic 100%. You can't send an Intent without having to meddle with some View stuff as well.

However, your model could still be made cleaner by making it more strictly MVP. Generally, the View should not contain any logic at all. That means it should also not decide what to do when an event - such as the user clicking some input button - occours. With that said, a cleaner approach to your situation would be

VIEW 1 [user action] => PRESENTER 1 => VIEW 1 [method to send intent]--{ Intent }--> VIEW 2 => PRESENTER 2 => MODEL 2

But the restriction of having to go through the View to send Intents is unfortunately one that is forced by Android.