0

我仅在 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)
4

1 回答 1

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>

我不确定为什么它只会在这个活动中表现得这样,因为我的应用程序中有其他活动声明了包引用并且工作正常,虽然奇怪。

于 2013-06-05T17:27:41.863 回答