在Android的隐式调用中,如果没有设置action只设置了Category就报ActivityNotFoundException;DEVGuide不是说如果Action,Category,Data通过测试就可以了吗,而且Intent的action也可以为空On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.
出错代码如下:(ActivityNotFoundException)
Test.java
Intent intent = new Intent(); //intent.setAction("testAction");//该行如果放开注释就正确 intent.addCategory("testCategory");//如果只设置action不添加category也正确 startActivity(intent);
AndroidManifest.xml
<activity android:name=".Test2"> <intent-filter> <action android:name="testAction"></action> <category android:name="testCategory"></category> <category android:name="android.intent.category.DEFAULT"></category> </intent-filter> </activity>
我想不会错的。
他都说了,只要过滤器包含至少一个动作,intent没有指定动作也会自动通过这个测试。
既然说了,那只能是可行的。可能还是哪写的不对呗。
呵呵 又是你啊
[quote]On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.[/quote]
这句话的意思,从另一方面说,一个没有指定一个action的Intent对象自动通过测试,但至少该fifer有一个action.
说白了,就是fifer不指定action的指向,也得把action写上。
能明白不?
而且要是自己定义的action 就必须指定action。
Intent中的category属性是一个执行Action的附加信息,必须要有一个Action的。Intent的使用详细信息可以参考[url]http://cuiquanmao.iteye.com/blog/789862[/url]
嗯 对头。
在你的xml中,一个Activity的IntentFilter中定义了Action
那么这个Intent也包含了相同的action,那就与这个目标Action匹配。
你的理解也对。
[quote]as long as the filter contains at least one action[/quote]
如果Intent不指定action 至少在fiter中有一个action。那它没有说需要其他别的,可能就是这样:
不确定。
要是intent指定了, 就要和fiter中的相同才能匹配。
你试试上面的,把其他的去掉。