Mainactivity.java
package com.example.demo16;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.view.view;import Android.view.View.OnClickListener ; Import Android.view.window;import Android.widget.button;import Android.widget.linearlayout;public class Mainactivity extends Activity implements Onclicklistener {@Overrideprotected void onCreate (Bundle savedinstancestate) { Remove the activity title requestwindowfeature (window.feature_no_title); super.oncreate (savedinstancestate);//annotation original layout// Setcontentview (R.layout.activity_main);//Instantiate layout linearlayout llayout = new LinearLayout (this);// Layout Direction llayout.setorientation (linearlayout.vertical);//Add to Window Setcontentview (llayout);//Instantiate button B = New button ( This), B.setonclicklistener (this);//Add the button to the layout Llayout.addview (b);} @Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubintent Intent = new Intent ("myaction"); intent.a Ddcategory ("MyCategory"); StartActivity (intent);}}
Androidmanifest.xml
Add a second activity to the file.
<application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@strin G/app_name "Android:theme=" @style/apptheme "> <activity android:name=" com.example.demo16.Ma Inactivity "android:label=" @string/app_name "> <intent-filter> <action an Droid:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!--This is the second activity start-and <ACTI Vity android:name= "com.example.demo16.SecondActivity" > <intent-filter> <action Android Oid:name= "Myaction"/> <category android:name= "mycategory"/> <!--this line means the default Categ Ory, be sure to write, if there is no mycategory, this line also to write--<category android:name= "Android.intent.category.DEFAULT"/> </intent-filtEr> </activity> <!--This is the second activity end---</application>
Run:
Click the button to jump to
Note: Because the secondactivity file and layout is relatively simple, the code is not posted here
The 13th chapter, the Implicit Intent Small demo (Android)