First, follow the wizard to create a project, layout of the Activity_main.xml file content is as follows:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <button android:id=" @+id/button " android:layout_width=" Match_parent " android:layout_height= "Wrap_content" android:text= "intent pass parameter test" /></relativelayout>
1) android:layout_width= "match_parent": Google changed the fill_parent to the actual effect more in line with the match_parent, said stuffed containers, plug meaning is how much space, occupy how much space
2) android:layout_height= "Wrap_content": Set to wrap_content full display of the text and images inside it. Layout elements will change size based on content. Setting the size of a view to Wrap_content is roughly equivalent to setting the AutoSize property of Windows controls to true.
3) Android:text: Set the display value of the button
Second, in the main function to do the intention to pass the parameter jump
protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); button = (button) This.findviewbyid (R.id.button); Button.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method stub <span style= " Color: #ff0000; " > Intent Intent = new Intent (mainactivity.this,otheractivity.class); Intent.putextra ("name", "Deng"); Intent.putextra ("Age", at a); StartActivity (intent); </span>});}
Start with the StartActivity method
Third, a new other.xml and Otheractivity.class
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" ><textview android:id= "@+id/msg" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" /> </LinearLayout>
public class Otheractivity extends Activity {private TextView textview;public otheractivity () {}protected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.other); TextView = (TextView ) This.findviewbyid (r.id.msg); <span style= "color: #ff0000;" >intent Intent = Getintent (); </span><span style= "color: #ff0000;" >string name = Intent.getstringextra ("name"); int = Intent.getintextra ("Age", 0); </span>textview.settext ( "Name" +name+ ";" + "age" +age);}}
Remember to override the OnCreate method and set the Setcontentview layout
Iv. Finally, add an activity tag to the file Androidmanifest.xml
<application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@ String/app_name " android:theme=" @style/apptheme "> <activity android:name=" Com.example.android_intent. Mainactivity " android:label=" @string/app_name "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <span style= "color: #ff0000;" > <activity android:name = ". Otheractivity " /></span> </application>
Android Intent transmission Parameters (iv)