I think peeps overcomplicated this. Just have some callback that tells your activity when to start Activity B from Fragments X, Y, or Z. Maybe do it in onAttach
.
Ex:
Fragment X
private MyCallback _myCallback;
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof MyCallback){
_myCallback =(MyCallback) context;
}
}
Now whenever something happens that you need to start Activity B, just do:
// Still in Fragment X
Intent intent = new Intent(this, ActivityB.class);
intent.putExtra("bloop", "frag_x"); // or "frag_y", "frag_z"
_myCallback.startActivityB(intent)
Now in Activity B just check the value of bloop
in the arguments and BAM. You know where it came from. I intentionally left some things out as an exercise. You can definitely make this more maintainable. Maybe use those OO skills to not duplicate the code that grabs that callback, etc.