1

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

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

i want to send String value from fragment1 to fragment2 without getting Null value. I hope you understand the problem. thanks

gonga dev
  • 117
  • 3
  • 13
  • A. You can store string value in fragment1 using application class object and then access it into fragment2. B. You can use localbroadcast receiver to send data. C. You can pass bundle to activity2 from fragment1 and then paas this bundle into fragment2. – Manish Jain Sep 10 '16 at 16:15

1 Answers1

1

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

Community
  • 1
  • 1
TapanHP
  • 5,969
  • 6
  • 37
  • 66