1, create the project File->new->android application in turn fill in the application name, project name, package nameLocate Src/com.example.helloworld mainactivity.java2 in the project catalog, add code
Package Com.example.helloworld;import Android.app.activity;import Android.content.intent;import android.os.Bundle; Import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;public class Mainactivity extends Activity { private button button; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); This.button = (Button) This.findviewbyid (r.id.button1); This.button.setOnClickListener (New Onclicklistener () { @Override public void OnClick (View v) { Intent Intent = new Intent (); Intent.setclass (Mainactivity.this, intentactivity.class); Intent.putextra ("name", "Hello World"); StartActivity (intent);}} );}}
Before adding the code, in Res/layout/activity_main.xml, drag a button control up. The information for the button is automatically generated in the Activity_main.xml, note the ID value, and if you use this button, 3, add jump activity1, right click Src/com.example.helloworld,new->class, fill in the name intentactivity, do not add Java can2, add layout. Right-click on res/layout, new->android XML file, drag a textview on this XML. The TextView address is automatically added to the R.java in this case.3, add the following code in Androidmanifest.xml: Complete the activity registration
<activity android:name= "Com.example.helloworld.IntentActivity" > </activity>
4. Realize Intentactivity.java
Package Com.example.helloworld;import Android.app.activity;import Android.os.bundle;import Android.widget.TextView Import Android.content.intent;public class Intentactivity extends activity{@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_intent); Intent Intent = Getintent (); String string = Intent.getstringextra ("name"); TextView TextView = new TextView (this); Textview.settextsize (+); Textview.settext (string); Setcontentview (TextView);}}
4, run open simulator or mobile phone, run.
3, the activity in the Android jump