One: Step:
1 Create the intent object, specifying the class to jump to in the parameter
2 Specifies the data to be uploaded to the next page through the Putextra () method of the intent object. Method parameters are used for key-value pairs.
3 initiates a jump by calling the StartActivity (Intent Intent) method or the Startactivityforresult (Intent intent,int requestcode) method.
Startactivtyforresult (): Activity a jumps to activity b,activity B can return data to activity a.
StartActivity (): Activity a jumps to activity B and can pass values.
4 after jumping to another activity, the bundle object can be obtained through the getintent (). Getextras () method, through the bundle object's GetString ()/getint () ... Method gets the value.
5 if it is through Startactivityforresult () jump activity, then the end of the jump activity will also be in the activity class jump to implement the Onactivityresult () method.
Two: examples
Packagecom.example.apploading;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classLauchingextendsActivity {PrivateEditText username=NULL; PrivateButton btn=NULL; PrivateOnclicklistener Mlistener =NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubIntent i=NewIntent (lauching. This, Exit.class); String s=Username.gettext (). toString (); I.putextra ("Name", s); //Startactivityforresult (i,r.layout.activity_exit);startactivity (i); } }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_loading); Username=(EditText) Findviewbyid (r.id.inputusername); BTN=(Button) Findviewbyid (r.id.lauching); Btn.setonclicklistener (Mlistener); }}
Packagecom.example.apploading;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.TextView; Public classExitextendsActivityImplementsonclicklistener{Button exitbtn; Button returnbtn; TextView Name; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_exit); EXITBTN=(Button) Findviewbyid (R.ID.EXITBTN); RETURNBTN=(Button) Findviewbyid (R.ID.RETURNBTN); Name=(TextView) Findviewbyid (r.id.name); String name=getintent (). Getextras (). getString ("name"); Name.settext (name); Exitbtn.setonclicklistener ( This); Returnbtn.setonclicklistener ( This); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.menu.exit, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a the parent activity in Androidmanifest.xml. intID =Item.getitemid (); if(id = =r.id.action_settings) { return true; } return Super. onoptionsitemselected (item); } @Override Public voidOnClick (View v) {//TODO auto-generated Method Stub Switch(V.getid ()) { CaseR.id.exitbtn:finish (); Break; Caser.id.returnbtn:intent i=NewIntent ( This, lauching.class); StartActivity (i); } } }
Android Development Learning Note (iii) activity jump and value transfer