How can I transfer data from one fragment to another fragment android

前端 未结 5 1330
梦如初夏
梦如初夏 2020-12-16 23:41

One way I know that is through activity.We can send data from fragment to activity and activity to fragment Is there any other way.

5条回答
  •  有刺的猬
    2020-12-17 00:19

    Allowing fragments to communicate with each other by using activities as their intermediaries is a common best practice when using fragments. Visit http://developer.android.com/guide/components/fragments.html for more details on this important pattern. Anytime you need to interact with another fragment, you should always use a method in the fragment’s activity rather than access the other fragment directly. The only time it makes sense to access one fragment from another is when you know that you won’t need to reuse your fragment in another activity. You should almost always write fragments assuming that you’ll reuse them rather than hard-code them to each other.

提交回复
热议问题