使用自定义意图投掷ACTIVITY NOT FOUND EXCEPTION启动活动

时间:2013-03-04 15:03:54

标签: android android-intent android-activity

我使用以下代码从我的应用程序中启动活动:

Intent intent = new Intent();
intent.setAction("com.android.excample.cutstom_action");
intent.setData(data); //public Uri data
intent.putExtra(Intent.Extra_stream, stream); // public Uri stream
startActivity(intent);

在另一个应用程序中,活动在清单文件中定义如下:

<activity android:name="MyActivity">
<intent-filter>
<action android:name="com.android.excample.cutstom_action"/>
<category android:name = "android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>

但是当我尝试启动活动时,我发现活动未找到异常。 请帮我解决这个问题

崩溃日志如下: “03-04 20:03:53.351: E/AndroidRuntime(22633): FATAL EXCEPTION: main 03-04 20:03:53.351: E/AndroidRuntime(22633): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/data/51826 flg=0x1 }} to activity {com.example.test/com.example.test.ContentPickerTester}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.excample.cutstom_action } 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread.deliverResults(ActivityThread.java:2983) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3026) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread.access$1100(ActivityThread.java:126) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1180) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.os.Handler.dispatchMessage(Handler.java:99) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.os.Looper.loop(Looper.java:137) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread.main(ActivityThread.java:4456) 03-04 20:03:53.351: E/AndroidRuntime(22633): at java.lang.reflect.Method.invokeNative(Native Method) 03-04 20:03:53.351: E/AndroidRuntime(22633): at java.lang.reflect.Method.invoke(Method.java:511) 03-04 20:03:53.351: E/AndroidRuntime(22633): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787) 03-04 20:03:53.351: E/AndroidRuntime(22633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) 03-04 20:03:53.351: E/AndroidRuntime(22633): at dalvik.system.NativeStart.main(Native Method) 03-04 20:03:53.351: E/AndroidRuntime(22633): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.excample.cutstom_action } 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.Activity.startActivityForResult(Activity.java:3190) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.Activity.startActivity(Activity.java:3297) 03-04 20:03:53.351: E/AndroidRuntime(22633): at com.example.test.ContentPickerTester.onActivityResult(ContentPickerTester.java:64) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.Activity.dispatchActivityResult(Activity.java:4649) 03-04 20:03:53.351: E/AndroidRuntime(22633): at android.app.ActivityThread.deliverResults(ActivityThread.java:2979)

1 个答案:

答案 0 :(得分:1)

设置“。”在清单文件中活动名称之前

".MyActivity"

或使用完全限定的路径设置它,如下所示:

"com.android.excample.MyActivity"