Returning data from an activity to another activity's fragment?-Collection of common programming errors

How can I pass data between an activity and a fragment belonging to another activity? I think that it should be something similar to passing data between activities through intents, but I’m not able to figure it out and couldn’t get any search result on it either.

For example, I have two activities A and B.

A has 3 fragments – “x”, “y” and “z”. Now I call B from “x” using startActivityForResult.

When I try and come back to “x” from “B” via setResult, it actually takes me to onActivityResult of “A” and not the one in “x…”. Plus the requestCode and resultCode are some number (65536) and -1 respectively.

Can anyone please help me with this?

  1. Most likely your parent activity inplements onActivityResult() too, but in that method you forgot to call super.onActivityResult(requestCode, resultCode, intent); to pass unhandled request codes. Or you got request code clash and the same code is expeceted by parent activity and the fragment.

Originally posted 2013-11-26 18:02:49.