Answer the question
In order to leave comments, you need to log in
How to organize data transfer from Activity to Presenter using MVP?
Hello. I'm trying to implement MVP in my application. I can’t figure out how to correctly transfer data from the activity to the presenter (for example, the entered text from edit text). It says that the activity should only notify the presenter that the data has been entered, and the decision to receive it should be made by the presenter. Those. now, conditionally, on entering text in edit text, the activity should call presenter.textReceived() and then in presenter view.getText().
With this approach, I have to create intermediate variables in activity. For example, I get the time from a custom DatePickerDialog using the OnTimeSetListener interface in an activity, and store the result in a variable. Then I notify the presenter that I have received the time, and in the presenter I call view.getTime().
How correct is this approach? What other solutions are used in practice?
Thank you!
Answer the question
In order to leave comments, you need to log in
No need to store intermediate data. The presenter immediately receives data from the view. presenter.setTime(time)
The presenter then decides what to do with them and if rendered then calls view.update(time)
By the way, be sure to separate the presenter and the activity interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question