mainActivity.java
package com.sxt.day04_07_twoaction; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity implements OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setListener(); } private void setListener() { findViewById(R.id.btn1).setOnClickListener(this); findViewById(R.id.btn2).setOnClickListener(this); } @Override public void onClick(View v) { Intent intent=new Intent(); intent.setAction("com.sxt.day04_07_twoaction.SecondActivity"); switch (v.getId()) { case R.id.btn1: intent.addCategory("com.sxt.day04_07_twoaction.category"); break; case R.id.btn2: intent.addCategory("android.intent.category.DEFAULT"); break; } startActivity(intent); } }
系统描述文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sxt.day04_07_twoaction" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.sxt.day04_07_twoaction.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> <activity android:name="com.sxt.day04_07_twoaction.SecondActivity" android:label="@string/title_activity_second" > <intent-filter> <action android:name="com.sxt.day04_07_twoaction.SecondActivity"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="com.sxt.day04_07_twoaction.category"/> </intent-filter> </activity> </application> </manifest>
本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/4886816.html,如需转载请自行联系原作者