我在Android 4.2.2上获取此异常(ActivityNotFound),同时从自定义视图启动活动。这适用于4.1.1及以下的所有设备。
有没有人遇到与4.2.2类似的问题?
从我的自定义视图启动活动的代码
Intent intent = new Intent(getContext(), MyActivity.class);
intent.putExtra(Constants.EXTRAS1, serializable);
intent.putExtra(Constants.EXTRAS2, serializable);
((Activity)getContext()).startActivityForResult(intent, Constants.MY_ACTION);
堆栈跟踪:
06-04 16:58:29.715: E/AndroidRuntime(20568): FATAL EXCEPTION: main
06-04 16:58:29.715: E/AndroidRuntime(20568): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sample.activity/com.sample.activity.MyActivity}; have you declared this activity in your AndroidManifest.xml?
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.Activity.startActivityForResult(Activity.java:3430)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.Activity.startActivityForResult(Activity.java:3391)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.View.dispatchTouchEvent(View.java:7461)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
06-04 16:58:29.715: E/AndroidRuntime(20568): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2186)
06-04 16:58:29.715: E/AndroidRuntime(20568): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1516)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
06-04 16:58:29.715: E/AndroidRuntime(20568): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2134)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.View.dispatchPointerEvent(View.java:7641)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3676)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3607)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4802)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4781)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4873)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.os.MessageQueue.nativePollOnce(Native Method)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.os.MessageQueue.next(MessageQueue.java:125)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.os.Looper.loop(Looper.java:124)
06-04 16:58:29.715: E/AndroidRuntime(20568): at android.app.ActivityThread.main(ActivityThread.java:5293)
06-04 16:58:29.715: E/AndroidRuntime(20568): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 16:58:29.715: E/AndroidRuntime(20568): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 16:58:29.715: E/AndroidRuntime(20568): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-04 16:58:29.715: E/AndroidRuntime(20568): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-04 16:58:29.715: E/AndroidRuntime(20568): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
好的,问题在于清单,
我将此活动在清单中声明为
<activity android:name="com.sample.MyActivity" android:theme="@android:style/Theme.Translucent"
android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
</activity>
从声明中删除包引用后开始工作,如下所示,
<activity android:name=".MyActivity" android:theme="@android:style/Theme.Translucent"
android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
</activity>
我不确定为什么它会以这种方式仅针对此活动的行为,因为我在我的应用程序中使用包引用声明了其他活动并且工作正常,但是很奇怪。