Android intent to send a parameter back result (vi)

Source: Internet
Author: User

For example, there are two pages, a, B. A page to pass parameters to the B page, b page will get the parameters processed, and then the results are returned to page a with parameters.

The code for the main mainactivity class of the 1.a page is as follows:

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

The parameter A is passed to page B,the Onactivityresult function handles the parameter C passed over the B page .

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




Android intent to send a parameter back 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.