如果我从邮件程序链接打开,Android应用程序将启动两次

时间:2015-03-27 11:20:13

标签: android performance android-intent android-activity android-launcher

即使此问题与this重复,也无法解决我的问题。 我的问题是当我通过邮件中的超链接启动应用程序时,我的应用程序再次打开作为新任务,即使应用程序已经在后台。我正在使用 机器人:launchMode = “标准”

如果我使用android:launchMode =“singleTask”,它解决了我的问题,但每当我从主屏幕启动应用程序时,即使应用程序处于后台,它也会从启动画面活动开始。请提出解决方案以解决上述两个问题。

我还了解了Google doc中的启动模式。但我的思想并没有那么多的知识值得观察。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用launchMode =" singleTask"

,这对我有用

将此添加到onCreate,你应该好好去:

if (!isTaskRoot()) {
        final Intent intent = getIntent();
        final String intentAction = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
            Log.w("LOG_TAG", "Main Activity is not the root.  Finishing Main Activity instead of launching.");
            finish();
            return;
        }
}

here回答。

谢谢伙伴。