-1

I have tried finding a answer for my question but could not find anything, so I have Activity A,Fragment A,Activity B.

Activity A is hosting Fragment A, and i need to pass some data from Fragment A to Activity B how can i make that possible? i Know how to pass data to the hosting activity but i'm getting confused when trying to pass it to Activity B, can some one post a example with explanation how to make it possible?

Kristjan
  • 33
  • 4
  • 1
    Obviously you should treat this case as normal activity - activity communication – Selvin Nov 25 '17 at 13:14
  • Pass the data back to your hosting Activity then follow [this](https://stackoverflow.com/questions/920306/sending-data-back-to-the-main-activity-in-android) to pass the data from that Activity to the next. – Gary99 Nov 25 '17 at 14:58

1 Answers1

1

You can simply use getActivity() or getContext() for getting activity context.

In your Fragment A, do like this.

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("key", "value");
    // here you pass data
    getActivity().startActivity(intent);
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212