当前分类 / 异常分析 / 总共1篇

在非 Activity 中使用 startActivity

在非 Activity 中使用 startActivity:Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

问题描述

在 APP 1 中启动 APP 2 中的 Activity。

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri1 = Uri.parse("xxxx://xxxx/page/link?url=http%3A%2F%2Fwww.baidu.com");
intent.setData(uri1);
Context context = getApplicationContext();
if (null != intent.resolveActivity(pm)) {
    context.startActivity(intent);
}

错误提示信息:

Caused by: Android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

阅读更多