easion_zms 2011-01-04 15:03 采纳率: 0%
浏览 591
已采纳

Intent只设置Category不设置Action难道不行吗?

在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>
  • 写回答

5条回答 默认 最新

  • 勤劳的小猿 2011-01-04 16:31
    关注

    我想不会错的。
    他都说了,只要过滤器包含至少一个动作,intent没有指定动作也会自动通过这个测试。
    既然说了,那只能是可行的。可能还是哪写的不对呗。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?