原文链接: https://www.cnblogs.com/bimingcong/p/10409914.html
方案一: 通过包名类名
ComponentName componentName = new ComponentName("com.example.bi", "com.example.bi.SplashActivity");//这里是 包名 以及 页面类的全称
Intent intent = new Intent();
intent.setComponent(componentName);
intent.putExtra("type", "110");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
1.在Activity上下文之外启动Activity需要给Intent设置FLAG_ACTIVITY_NEW_TASK标志,不然会报异常。
2.加了该标志,如果在同一个应用中进行Activity跳转,不会创建新的Task,只有在不同的应用中跳转才会创建新的Task
方案二:通过intent的 action
在目标Activity的配置文件中添加具体的action
<!--ACTION启动配置-->
<intent-filter>
<action android:name="com.example.bi" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Intent intent = new Intent();
intent.setAction("com.example.bi");
intent.putExtra("type", "110");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
方案三:通过Uri
<!--URL启动启动配置-->
<intent-filter>
<data
android:host="com.example.bi"
android:path="/cyn"
android:scheme="csd" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Intent intent = new Intent();
intent.setData(Uri.parse("csd://com.example.bi/cyn?type=110"));
intent.putExtra("", "");//这里Intent当然也可传递参数,但是一般情况下都会放到上面的URL中进行传递
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
PS:
启动app之前要判断下是否有安装这个app可以参考下面的链接的第一步和第三步
https://blog.csdn.net/qq_38287890/article/details/91416925