backhaul data for Android activity

Source: Internet
Author: User
Tags response code

1  Packagecom.example.myact3;2 3 Importandroid.content.Intent;4 ImportAndroid.os.Bundle;5 Importandroid.support.v7.app.ActionBarActivity;6 ImportAndroid.view.View;7 ImportAndroid.view.View.OnClickListener;8 ImportAndroid.widget.Button;9 ImportAndroid.widget.TextView;Ten /** One * Callback data for Android activity A  * @authorshaobn -  * -  */ the  Public classMainactivityextendsactionbaractivity { -     Privatebutton button;  -     PrivateTextView TV; -     Private Static Final  intREQUEST = 1; + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity_main); atButton = (Button) This. Findviewbyid (r.id.button1); -TV = (TextView) This. Findviewbyid (r.id.textview1); -Button.setonclicklistener (NewOnclicklistener () { -              - @Override -              Public voidOnClick (View arg0) { in                 //TODO auto-generated Method Stub -Intent Intent =NewIntent (mainactivity. This, MainActivity2.class); toIntent.putextra ("Text", Tv.gettext ()); +                 //This method makes a request to carry its own request code, which is convenient to verify when it comes back - Startactivityforresult (intent,request); the             } *         }); $     }Panax Notoginseng     //Requestcode Request code to match the request code of the requested activity -     //ResultCode Response code to receive data consistent with the response code set by this activity.  the     //the intent object passed by data on the second page. + @Override A     protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { the         //TODO auto-generated Method Stub +         Super. Onactivityresult (Requestcode, ResultCode, data); -         if(resultcode==2){ $             if(requestcode==REQUEST) { $String string = Data.getstringextra ("Response"); -                  This. Tv.settext (string); -             } the         } -     }Wuyi      the}
1  Packagecom.example.myact3;2 3 Importandroid.content.Intent;4 ImportAndroid.os.Bundle;5 Importandroid.support.v7.app.ActionBarActivity;6 ImportAndroid.view.View;7 ImportAndroid.view.View.OnClickListener;8 ImportAndroid.widget.Button;9 ImportAndroid.widget.TextView;Ten  One  Public classMainActivity2extendsactionbaractivity { A     PrivateTextView TV; -     Privatebutton button; - @Override the     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main_activity2); -Button = (Button) This. Findviewbyid (r.id.button1); +TV = (TextView) This. Findviewbyid (r.id.textview1); -Tv.settext ("Olympic Games"); +Button.setonclicklistener (NewOnclicklistener () { A              at @Override -              Public voidOnClick (View arg0) { -                 //TODO auto-generated Method Stub -Intent Intent =NewIntent (); -Intent.putextra ("Response", Tv.gettext ()); -                 //back to the activity that got the focus before inSetresult (2, intent); -                 //End Declaration Cycle to finish (); +             } -         }); the          *     } $}

backhaul data for Android activity

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.