The only solution I've found so far is a set of utility methods, that is a mix of Intents and EventBus from greenrobot:
public class ActivityUtils {
public static void startForResult(Activity context, Class<?> destinationActivity, Object param) {
Intent intent = new Intent(context, destinationActivity);
EventBus.getDefault().postSticky(param);
context.startActivityForResult(intent, 0);
}
public static void returnSuccessfulResult(Activity context, Object result) {
Intent returnIntent = new Intent();
EventBus.getDefault().postSticky(result);
context.setResult(Activity.RESULT_OK, returnIntent);
context.finish();
}
public static <T> T getParameter(Class<T> type) {
return EventBus.getDefault().removeStickyEvent(type);
}
}
In my FirstActivity I call somethig like:
ActivityUtils.startForResult(this, SecondActivity.class, new MyParam("abc", 123));
After that in the SecondActivity I call:
MyParam param = ActivityUtils.getParameter(MyParam.class);
When I finish the SecondActivity:
ActivityUtils.returnSuccessfulResult(this, new MyResult("xyz"));
And then in the FirstAcivity:
MyResult result = ActivityUtils.getParameter(MyResult.class);