Android MVP: one action with multiple fragments

I have an Activity that contains several fragments that define each step in the registration stream for the user. The flow is complex, and the next step is determined by the actions of the user in the previous steps.

The stream is as follows:

MainActivity | Fragment1 --> Fragment2 --> Fragment3 --> Fragment4
                                       \
                                        --> Fragment5 --> Fragment6

After MVP, I have a View and Presenter for each participating fragment. My concern is how to communicate between Fragment and Activity in MVP. The result of each Fragment should be available for the Action in order to decide which fragment should be shown next.

One of the approaches that I was thinking about is to have a listener defined for each fragment that the Activity implements. I somehow think this is a little ugly, because at the end of the Activity you need to implement 6 of them and does not look scalable.

What would be the best approach?

+4
source share
2 answers

As you already mentioned, you want to communicate with fragments using MVP. According to me, I found 2 solutions.

1:      , , /. .

2:     Event Buses - , MVP, . , : . , . , , , .

. . , . , , , , , . EventBus , .

Event Buses :  - GreenBot: https://github.com/greenrobot/EventBus  - : http://www.vogella.com/tutorials/JavaLibrary-EventBusOtto/article.html

Activity/Fragments, . , , .

+2

, Fragment Activity. :

enter image description here

+3

Source: https://habr.com/ru/post/1666481/


All Articles