Android Intent pass parameter return result (vi)

Source: Internet
Author: User

For example, there are two pages, a, B.

A parameter is passed to page B, after B, the processing page of the parameter is obtained, and the result is then passed back to page a with the parameter.

1.a Home mainactivity code type, such as the following:

    Private button button;    Private EditText result;    Private final static int requestcode = 1;
    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);                Setcontentview (r.layout.activity_main);        Button = (button) This.findviewbyid (r.id.button1);        result = (EditText) This.findviewbyid (r.id.result);                Button.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method stub
Intent Intent = new Intent (mainactivity.this,otheractivity.class); Intent.putextra ("A", "true"); Startactivityforresult (Intent,requestcode);}});            }
<pre name= "code" class= "HTML" >    @Override    protected void onactivityresult (int requestcode,int Resultcode,intent data) {    Super.onactivityresult (Requestcode, ResultCode, data);    if (ResultCode = = 2) {    if (Requestcode = = Requestcode) {
                        <span style= "font-family:arial, Helvetica, Sans-serif;" >string c= Intent.getstringextra ("C");</span>    Result.settext (c);}}        

Pass the argument A to page B,the Onactivityresult function handles the number of references that are passed to page B .

<span style= "font-family:arial, Helvetica, Sans-serif;" ></span>
<span style= "font-family:arial, Helvetica, Sans-serif;" After the >2.otheractivity.java function processes a parameter, the C parameter is passed back to the a page. In the B page of the OnCreate inside processing </span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ></span><pre name= "code" class= "HTML" >   <pre name= "code" class= "html" > @Overridepublic void OnClick (View arg0) {//TODO auto-generated method stub        Intent Intent = Getintent ();        String a = Intent.getstringextra ("a");        String C;        if (a== "true") {        c = "It is true";        } else{        C = "It is false";        }        Intent newintent = new Intent () Newintent.putextra ("C", c); Setresult (2,intent); Finish ();});




Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android Intent pass parameter return result (vi)

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.