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