How to pass data from fragment to another - android

后端 未结 1 1366
旧巷少年郎
旧巷少年郎 2021-01-24 16:14

I have two activities with fragment1 inside activity1 and fragment2 inside activity2

fragment1 and fragment2 extend from Fragment activity1 and activity2 extend from App

相关标签:
1条回答
  • 2021-01-24 16:49

    Best way to achieve this is using singleton pattern, you can use it for fragment-fragment, fragment-activity communication.

    See this answer, it explained with code there and in a very meaningful way. but what i preferred from my experience is you should user EventBus if you want to handle bigger projects with many fragments and larger dependencies, connections and data flows within and between fragments and activities.

    The basic communication can be done as per suggested in Developer documentation here

    0 讨论(0)
提交回复
热议问题