Android Intent transmission Parameters (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.