Day126 — pass data back to source fragment

Jacky Tsang
1 min readDec 2, 2019

--

A common scenario in android application is that some data is needed to send back to the source from the destination fragment.

Let define the scenario as below:

  1. source fragment starts destination fragment
  2. new data occurs in destination
  3. destination want to pass that data back to source

For Activity, you can use setResult to pass intent back to the source activity

For fragment, you can use setTargetFragment to state the who is the source so that that is a reference to the source fragment in destination fragment. Data can be easily passed back to source using intent.

--

--

No responses yet