Communicating between more than 2 fragments

前端 未结 2 1911
天命终不由人
天命终不由人 2020-12-22 02:24

I have an activity with three fragments in it, This is how I communicate between the three fragments:

First I display only FragmentA in ActivityA<

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 02:49

    In such circumstances in which multiple fragments and activities want to communicate with each other, two options come in mind.

    • Java Interfaces - Only one activity and one or more fragments. Each fragment should implement its own interface. Activity is also used for a shared channel among them. Recommended

    Image source: https://stackoverflow.com/a/24083101/1841194

    • Local broadcasts - Can be used among multiple activities and services. This also can be used for communicating between fragments.

提交回复
热议问题