我想用下面的代碼發起的活動:錯誤,同時通過意向開展活動
Intent i = new Intent();
i.setClassName("com.android.launcher2", "com.android.launcher2.Launcher");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
我得到上面這段代碼以下異常:
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.LOCALE_CHANGED flg=0x30 } in [email protected]
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.os.Handler.handleCallback(Handler.java:605)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.os.Handler.dispatchMessage(Handler.java:92)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.os.Looper.loop(Looper.java:137)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.ActivityThread.main(ActivityThread.java:4368)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at java.lang.reflect.Method.invoke(Method.java:511)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at dalvik.system.NativeStart.main(Native Method)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.launcher2/com.android.launcher2.Launcher}; have you declared this activity in your AndroidManifest.xml?
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.ContextImpl.startActivity(ContextImpl.java:889)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at com.android.launcher2.LauncherModel.onReceive(LauncherModel.java:634)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
01-01 00:05:03.617: ERROR/AndroidRuntime(1458): ... 9 more
我試圖啓動來自同一包中類的活動 - com.android.launcher2
,並且我在清單中定義了此活動(Launcher
)。
可有人請讓我知道是什麼原因導致這個錯誤,雖然一切看起來OK
編輯
Intent i = new Intent(getApplicationContext(), com.android.launcher2.Launcher.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
我有完全做到了這一點,並進行測試。現在,活動按以下順序繼續進行 - onNewIntent()
,onResume()
。相反,我需要onDestroy()
和onCreate()
序列發生。我怎樣才能做到這一點?任何人在這方面的幫助,非常感謝
我認爲你的清單文件存在問題,在manifest.xml中聲明你的類 – 2012-03-26 12:02:28