Android的意图来启动应用程序的主要活动 [英] Android Intent to start Main activity of application

查看:218
本文介绍了Android的意图来启动应用程序的主要活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个BroadcastReceiver内启动的主要活动。
我不想提供的活动表名,而使用Android的动作和类别找出主要的活动。

I am trying to start the main activity from inside a BroadcastReceiver. I dont want to supply the activity class name but to use the action and category for android to figure out the main activity.

它似乎没有工作。

发送code:

Intent startIntent = new Intent();

startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startIntent.setAction(Intent.ACTION_MAIN);
startIntent.setPackage(context.getPackageName());
startIntent.addCategory(Intent.CATEGORY_LAUNCHER);        
context.startActivity(startIntent);

我得到这个错误:

I get this error:

引起BT:android.content.ActivityNotFoundException:无活动处理意向{
  ACT = android.intent.action.MAIN猫= [android.intent.category.LAUNCHER]
  FLG = 0x10000000处PKG = com.xyz.abc(有临时演员)}

Caused bt: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.xyz.abc (has extras) }

任何想法?

推荐答案

这是不是给startActivity的正确方法。结果
试试这个code来代替:

this is not the right way to startActivity.
try this code instead:

Intent startIntent = new Intent(context, MainActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        
context.startActivity(startIntent);

这篇关于Android的意图来启动应用程序的主要活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆