2012-03-26 79 views
0

我想用下面的代码发起的活动:错误,同时通过意向开展活动

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()序列发生。我怎样才能做到这一点?任何人在这方面的帮助,非常感谢

+0

我认为你的清单文件存在问题,在manifest.xml中声明你的类 – 2012-03-26 12:02:28

回答

1

您是否注销了onStop()中的LauncherModel中的所有广播接收器?

1

试试这个:

 Intent i = new Intent(getApplicationContext(), com.android.launcher2.Launcher.class); 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(i); 
1

类未发现异常意味着......无论你有没有在您的清单文件中定义的类或正在制作的类explicitly..so检查你清单文件。

,做在你activity--

Intent intent = new Intent(act1.this, act2.class); 
    startActivity(intent); 
+0

将尝试所有的答案并更新导致问题的原因,如果其中任何一个帮助我解决问题的话。 – user264953 2012-03-26 12:20:14

3

关注这个:


在Java

Intent i = new Intent(); 
    i.setClassName("com.android.launcher2", "com.android.launcher2.Launcher"); 
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(i); 

在清单

 <activity android:name="com.android.launcher2.Launcher" class="com.android.launcher2.Launcher"> 
     </activity> 
0

除了你的编辑:看看你的意图标志我认为有问题看看android dev,他们明确表示,这个标志通常与多个标志结合。