从我的自定义主屏幕启动时,相机和地图崩溃

时间:2011-12-21 07:21:25

标签: android android-activity android-intent launcher homescreen

我创建了一个自定义主屏幕。 这是我点击时启动应用程序的代码:

mainIntent = packageManager.getLaunchIntentForPackage(strPackageName);
if(mainIntent!=null)
{
    mainIntent = mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
                           .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    startActivity(mainIntent);
}

一切正常,但启动相机或谷歌地图时我得到一个例外:

E/AndroidRuntime(845): FATAL EXCEPTION: main
E/AndroidRuntime(845): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.camera/com.android.internal.app.ResolverActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime(845):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
E/AndroidRuntime(845):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
E/AndroidRuntime(845):  at android.app.Activity.startActivityForResult(Activity.java:2858)
E/AndroidRuntime(845):  at android.app.Activity.startActivity(Activity.java:2964)
E/AndroidRuntime(845):  at com.gears42.surelock.ApplicationLauncher.onItemClick(ApplicationLauncher.java:34)
E/AndroidRuntime(845):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime(845):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
E/AndroidRuntime(845):  at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(845):  at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(845):  at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime(845):  at android.app.ActivityThread.main(ActivityThread.java:4914)
E/AndroidRuntime(845):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(845):  at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(845):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(845):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(845):  at dalvik.system.NativeStart.main(Native Method)


E/AndroidRuntime(872): FATAL EXCEPTION: main
E/AndroidRuntime(872): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.apps.maps/com.android.internal.app.ResolverActivity}; have you declared this activity in your AndroidManifest.xml?
E/AndroidRuntime(872):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
E/AndroidRuntime(872):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
E/AndroidRuntime(872):  at android.app.Activity.startActivityForResult(Activity.java:2858)
E/AndroidRuntime(872):  at android.app.Activity.startActivity(Activity.java:2964)
E/AndroidRuntime(872):  at com.gears42.surelock.ApplicationLauncher.onItemClick(ApplicationLauncher.java:34)
E/AndroidRuntime(872):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime(872):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
E/AndroidRuntime(872):  at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(872):  at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(872):  at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime(872):  at android.app.ActivityThread.main(ActivityThread.java:4914)
E/AndroidRuntime(872):  at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(872):  at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(872):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(872):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(872):  at dalvik.system.NativeStart.main(Native Method)

我正在使用2.2.1 HTC Wildfire(同样适用于Android 3.1 Samsung Galaxy Tab)

任何建议/解决方法??

2 个答案:

答案 0 :(得分:0)

这部分看起来很奇怪:

E/AndroidRuntime(872): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.apps.maps/com.android.internal.app.ResolverActivity}; have you declared this activity in your AndroidManifest.xml?

您是否尝试将其添加到清单中?

答案 1 :(得分:0)

使用Intent intend = new Intend(new ComponentName(packakeName, className));代替