suppose that you have 3 Activities (A, B and C) and Activity A starts B, and B starts C.
I need that activity C delivery result to Activity A, because activity B is finished when starts activity C.
This code do not works:
public class ActivityA extends Activity {
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == ActivityC.REQUEST_CODE) {
// need this code be called when activityC finish
}
super.onActivityResult(requestCode, resultCode, data);
}
}
public class ActivityB extends Activity {
void startActivityC() {
Intent intent = new Intent();
intent.setClass(this, ActivityC.class);
startActivityForResult(intent, ActivityC.REQUEST_CODE);
finish();
}
}
public class ActivityC extends Activity {
public static final int REQUEST_CODE = 12345;
void finishActivity() {
Intent intent = new Intent();
intent.putExtra("example", "example");
setResult(RESULT_OK, intent);
finish();
}
}
Any idea how to implement this?
Thank you!
The problem is you’re essentially trying to send a note from point C to point A, and it has to go through point B, but point B decides it doesn’t want to pass notes anymore and goes off to do its own thing. So the note just disappears.
In Activity B, you already tell it you’re starting the activity for a result, so rather than calling finish after starting Activity C, handle the activity result instead and then finish:
This will allow Activity B to receive the result it requested from Activity C, then pass it along back to Activity A.
Hope that helps.