Use case = 2 fragments hosted by the same activity.
Where startActivityForResult()
establishes a relationship between 2 activities, setTargetFragment()
defines the caller/called relationship between 2 fragments.
setTargetFragment(target) lets the "called" fragment know where to send the result. onActivityResult()
is called manually in this case.
public class Caller extends Fragment
Fragment called = Called.newInstance()
called.setTargetFragment(this)
public class Called extends DialogFragment
intent = amazingData
getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, intent)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…