First modify the Values\strings.xml file
The code is as follows:
<resources> <string name= "app_name" >mytab</string> <string name= "Menu_settings" > settings</string> <string name= "app_title" >intent operation </string><string name= "Send_name" > Send Intent Activity program. </string><string name= "Receive_name" > Receive Intent Activity Program .</string> </resources>
Then define the Send_main.xml file
The code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " xmlns:tools=" Http://schemas.android.com/tools " android:id=" @+id/mylayout " android:layout_ Width= "Fill_parent" android:layout_height= "fill_parent" tools:context= ". Mainactivity "><button android:id=" @+id/mybut " android:layout_width=" Wrap_content " android: layout_height= "Wrap_content" android:text= "Press to jump to another activity program"/></linearlayout>
The corresponding definition Send.java class
The code is as follows:
Package Com.example.mytab;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 Send Extends Activity {private Button mybut = null; @Override public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.send_main); This.mybut = (Button) Super.findviewbyid (r.id.mybut); This.mybut.setOnClickListener (New Onclicklistenerlmpl ()); } public class Onclicklistenerlmpl implements onclicklistener{public void OnClick (view view) { Intent it = new Int ENT (send.this,receive.class); It.putextra ("MyInfo", "Hi, Friend"); Send.this.startActivity (it);}}}
For receive, there is a corresponding definition
First Receive_main.xml file
The code is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/mylayout " android:layout_width=" fill_parent " android:layout_height=" fill _parent " android:orientation=" vertical "> <textview android:id=" @+id/show " android:layout _width= "Wrap_content" android:layout_height= "Wrap_content"/></linearlayout>
Then define the Receive.java class
The code is as follows:
Package Com.example.mytab;import Android.app.activity;import Android.content.intent;import android.os.Bundle; Import Android.widget.textview;public class Receive extends activity{private TextView show = null; @Overridepublic void on Create (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Super.setcontentview (R.layout.receive_main ); this.show = (TextView) Super.findviewbyid (r.id.show); Intent it = super.getintent (); String info = It.getstringextra ("MyInfo"); This.show.setText (info);}}
Finally need to modify the corresponding Mainifest.xml file, add new activity Program
The code is as follows:
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.mytab " Android:versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= " android:targetsdkversion= "/> <application android:icon=" @drawable/ic_launcher " android: Label= "@string/app_name" android:theme= "@style/apptheme" > <activity android:name= "Send" android:label= "@string/send_name" > <intent-filter> <action android:name= " Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name= "Receive" Android:label = "@string/receive_name"/> </application></manifest>
Operating effect:
Click to jump to another activity class and pass the message
Android's first knowledge of intent