lordneru
lordneru

Reputation: 770

Pass data from a view to a another model view in Android MVP

In my MVP App, I have two activities (Views). The first get the input data from user, which will need the model of the second activity to get data from repo.

Currently, I have the following chain:

Data in VIEW 1 --{ Intent }--> VIEW 2 => PRESENTER 2 => MODEL 2

I would like to know whether is another cleaner or better way to get the same result. Data is optional - so it may not always be passed thru.

Upvotes: 0

Views: 349

Answers (1)

Namnodorel
Namnodorel

Reputation: 385

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.

Upvotes: 0

Related Questions