Fragment 2 fragment communicating

后端 未结 4 930
一向
一向 2020-12-21 01:24

Why i should use the Communicating with Other Fragments pattern when I could simply use

((MyActivity)getActivity()).doFoo();

In my Fragmen

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 02:00

    Communicating between fragments should be only through activity. ((MyActivity)getActivity()).doFoo() - will call a method in activity and then update the other fragment

    Fragment should be control only by the activity. Say.. if an fragment has a direct way to communicate with the other fragment , then there are possible that an fragment can be detached from other fragment without the activity aware.

提交回复
热议问题