Android -- pass FLAG_ACTIVITY_FORWARD_RESULT for multiple Ativity values

Source: Internet
Author: User

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();}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.