Android -- pass FLAG_ACTIVITY_FORWARD_RESULT for multiple Ativity values
Applicability: transfer the values of multiple activities. ActivityA arrives at ActivityB and then reaches ActivityC, but ActivityB can finish the transition page. At this time, ActivityC transparently transmits the value to ActivityA.
In fact, you only need to use the FLAG_ACTIVITY_FORWARD_RESULT of Intent.
Page 1: Jump A to B
public class ActivityA extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(this, ActivityB.class);startActivityForResult(intent, 100); } @Override protected void onActivityResult(int arg0, int arg1, Intent arg2) { super.onActivityResult(arg0, arg1, arg2); if(arg2 != null) { Log.e("yanru", "requestCode="+arg0+",resultCode="+arg1+",data="+arg2.getIntExtra("a", 8)); } }}Transition page: There are more transition pages in the middle. B to C
public class ActivityB extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Intent intent = new Intent(this, ActivityC.class);intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);startActivity(intent);finish();}}C. Pass the value and obtain the value in OnActivityResult of.
public class ActivityC extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Intent intent = getIntent();intent.putExtra("a", 8);setResult(Activity.RESULT_OK, intent);finish();}}