简体   繁体   English

如何从另一个应用程序启动活动?

[英]How to launch an activity from another app?

I dont know what I am doing wrong. 我不知道我在做什么错。 I am trying to launch an activity of another app from current app. 我正在尝试从当前应用程序启动另一个应用程序的活动。
Here is the code: 这是代码:

  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

    Intent intent = new Intent(Intent.ACTION_MAIN); 
    intent.setComponent(new ComponentName("com.second.package","com.second.package.SecondActivity")); 
    startActivity(intent); 

}

When I run this thing it says Application closed unexpectedly. 当我运行这个东西时,它说应用程序意外关闭。 What is wrong? 怎么了? Please help me. 请帮我。

Succeded: Just add : 成功:只需添加:

android.intent.category.DEFAULT

to the activity in the manifest file. 清单文件中的活动。

try as: 尝试为:

Intent intent = new Intent("android.intent.action.MAIN"); 
intent.setComponent(new   
ComponentName("com.second.package","com.second.package.SecondActivity")); 
intent.addCategory("android.intent.category.LAUNCHER");
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM