隐式调用intent报错,找不到原因,请指点,谢谢
public class MainActivity extends Activity {
public final static String MY_ACTION = "com.zkbao.intentactioncategorytest.action.MY_ACTION";
public final static String MY_CATEGORY="com.zkbao.intentactioncategorytest.category.MY_CATEGORY";
private Button startBtn = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startBtn = (Button)findViewById(R.id.startBtn);
startBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(); //隐式调用,传递自定义的Action和category
intent.setAction(MainActivity.MY_ACTION);
intent.addCategory(MainActivity.MY_CATEGORY);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
第二个SecondActivity源码
public class SecondActivity extends Activity {
private TextView actionShowText=null;
private TextView categoryShow=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
actionShowText = (TextView)findViewById(R.id.actionShow);
categoryShow = (TextView)findViewById(R.id.categoryShow);
actionShowText.setText("action is: "+getIntent().getAction());
Set<String> cate = getIntent().getCategories();
categoryShow.setText("category is: "+cate);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
}
mainfest配置部分
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.zkbao.intentactioncategorytest.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.zkbao.intentactioncategorytest.SecondActivity"
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="com.zkbao.intentactioncategorytest.action.MY_ACTION"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.zkbao.intentactioncategorytest.category.My_CATEGORY"/>
</intent-filter>
</activity>
</application>
可是运行程序,一点MainActivity按钮,报错:

看了很多网上都说是配置文件配置有问题,一般都是少了<category android:name="android.intent.category.DEFAULT" />,可是我已经加上了,还是出错,请指点,谢谢
相关推荐
调用Android系统设置中的Intent
开发Android软件时,常常需要打开系统设置或信息界面,来设置相关系统项或查看系统的相关信息,这时我们就可以使用以下语句来实现:(如打开“无线和网络设置”界面)
系统intent的使用例子
系统intent的使用例子:google搜索,打开浏览器,打电话,发送短信,彩信,发邮件,打开摄像机,打开图库,播放音乐,打开录音等等,对应博客文章 Intent之系统Intent<一>
Using-Android-Implicit-Intents:安卓
Using-Android-Implicit-Intents 展示如何通过隐式意图传递数据。
android4.0混淆XmlPullParser报错原因分析解决
今天,用android4.0在proguard-project.txt中加入 -libraryjars libs/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar这句话后,混淆时报上面的错误,下面与大家分享下具体的解决方法
Android中Intent传递对象的两种方法Serializable,Parcelable
Android中的传递有两个方法,一个是Serializable,另一个是Parcelable。 Serializable是J2SE本身就支持的。而Parcelable是Android所特有的。 二者的使用场景和区别: 1)在使用内存的时候,Parcelable比Serializable性能高,所以推荐使用Parcelable。 2)Serializable在序列化的时候会产生大量的临时变量,从而引起频繁的GC。 3)Parcelable不能使用在要将数据存储在磁盘上的情况,因为Parcelable不能很好的保证数据的持续性在外界有变化的情况下。尽管Serializable效率低点,但此时还


