从广播接收器开始另一个应用

时间:2011-12-16 16:22:41

标签: android android-activity broadcastreceiver

我试图在设备启动后从Receiver启动一个活动:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER); 
context.startActivity(intent);

当我从我的活动中调用它时,此代码工作正常但是当我的BroadcastReceiver在启动后执行它时它失败了。我的Logcat显示:

ActivityNotFoundException: Have you declared the activity in your AndroidManifest.xml?

任何指针都将非常感激。提前谢谢。

3 个答案:

答案 0 :(得分:1)

  

Intent intent = new Intent(context,activity.class);       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);       context.startActivity(意向);

我认为这3行只需要,上下文将是你在广播接收器中收到的上下文。

答案 1 :(得分:0)

当您在清单中声明活动时,您可能拼写错误或犯了错误。确保你把它放在那里并拼写正确的一切

答案 2 :(得分:0)

我认为问题出现在以下行中。您的Activity的名称是什么?是“ActivityName”吗?还检查包名。

intent.setComponent(ComponentName.unflattenFromString("other.apps.package.name/.ActivityName"))
相关问题