I. Create a new Empty project
Two. Add a button to the main interface
Three. Create a new empty activity and name it Theaty
Four. Modifying the OnCreate function in Mainactivity.java
protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (R.id.btnstartaty). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent I=NewIntent (mainactivity. This, Theaty.class); I.putextra ("Data", "Hello Android");//Pass a string argument with the name value "Data" and the value "Hello AndroidStartActivity (i);//Start another activity } }); }
Five. Add the ID number to the TextView in the Theaty layout file
<android:text= "@string/hello_world" android:layout_width= "Wrap_ Content " android:layout_height=" Wrap_content " android:id=" @+id/ TV "/>
Six. Modify the OnCreate function in the Theaty source code file
Private TextView TV; // First, add a TextView member variable protected void onCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_the_aty); = Getintent (); // get the relevant intent TV = (TextView) Findviewbyid (r.id.tv); Tv.settext (I.getstringextra ("Data")); // set the value in the text box }
Seven. Running
Transfer simple data when activity jumps