Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android从我的应用程序启动两个应用程序_Android - Fatal编程技术网

Android从我的应用程序启动两个应用程序

Android从我的应用程序启动两个应用程序,android,Android,好的,我有这个代码,出于某种原因,它只启动最后一个意图,而不是第一个意图。有什么建议吗 private void launchApps(String m) { if (m.equals("Two")) { Intent a = getPackageManager().getLaunchIntentForPackage("Firstapp"); startActivity(a); Intent b = getPackageManager().get

好的,我有这个代码,出于某种原因,它只启动最后一个意图,而不是第一个意图。有什么建议吗

private void launchApps(String m)
{
   if (m.equals("Two"))
   {
      Intent a = getPackageManager().getLaunchIntentForPackage("Firstapp");
      startActivity(a);

      Intent b = getPackageManager().getLaunchIntentForPackage("Secondapp");
      startActivity(b);
   }
}
但是由于某些原因,只有意图b启动,而不是a。你试过这个吗

private void launchApps(String m)
{
   if (m.equals("Two"))
   {
      Intent a = new Intent(this, FirstActivity.class);
      startActivity(a);

      Intent b = new Intent(this, SecondActivity.class);
      startActivity(b);
   }
}
如果它不起作用

试试这个

Intent a = getPackageManager().getLaunchIntentForPackage("Firstapp");
    startActivity(a);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            Intent b = getPackageManager().getLaunchIntentForPackage("Secondapp");
            startActivity(b);
        }
    }, 500);

尝试在
startActivity(b)之前放置断点。我敢打赌,
A
启动的那一刻,
B
立即启动并取代
A
。只有一个可能的应用程序可以立即启动。它们不是类,而是手机上安装的另外两个应用程序。就像谷歌浏览器和谷歌地图一样。@Jayce ok,然后查看我的更新代码。希望对你有帮助。这是我的荣幸:)