[英]Use intent to launch app
I am implementing the intent to launch an application inside service. 我正在实现在服务内部启动应用程序的意图。 It's working fine when I pass other applications package names, but it's showing exception when I call the same package name where I have implemented the intent.
当我传递其他应用程序的程序包名称时,它工作正常,但是当我在实现意图的地方调用相同的程序包名称时,则显示异常。 It's showing like " have you declared it manifest or not ?".
它显示为“您是否声明了清单?”。 It's already declared in manifest.
它已在清单中声明。
Intent nextIntent = new Intent(Intent.ACTION_MAIN);
nextIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nextIntent.setComponent(new ComponentName("com.example.app1","com.example.app1.MainActivity"));
startActivity(nextIntent);
If I replace the package name , it's working fine. 如果我替换软件包名称,则可以正常工作。 How to do it?
怎么做?
start the activity in the standard way: 以标准方式开始活动:
Intent nextIntent = new Intent(context_reference, MainActivity.class);
nextIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nextIntent.setAction(Intent.ACTION_MAIN);
startActivity(nextIntent);
If you pass strings, you're screwed in case of a refactoring - if you forget to modify the string as well. 如果传递字符串,那么在进行重构时会很费劲-如果您也忘记修改字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.