Android的launchmode =" singleTask"不能按预期工作 [英] Android launchmode="singleTask" does not work as expected

查看:160
本文介绍了Android的launchmode =" singleTask"不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在后台运行,并显示经由通知系统的错误信息的应用程序。该通知有pendingIntent,导致后面的应用程序的主屏幕。在这个主屏幕上,我已经设置launchmode =singleTask。我的理解是从Android开发指南,这应该意味着,我的主要活动将永远只能有一个实例。

I have an application that runs in the background, and displays an error message via the notifications system. This notification has a pendingIntent that leads back the the app's main screen. On this main screen, I have set launchmode="singleTask". As I understand it from the Android Dev Guide, this should mean that my main activity will only ever have one instance.

但是,如果用户正在观看该活动的时候(或在应用程序内另一个),并进入和触摸通知以清除它,它会开始放活动的另一个副本栈上,因此,如果我打的后退按钮,它会再次返回到主屏幕(从主屏幕)。

However, if the user is viewing that activity at the time (or another one within the app), and goes and touches the notification to clear it, it goes ahead and puts another copy of the activity on the stack, so if I hit the back button, it will return to the main screen again (from the main screen).

为什么会做这个?

推荐答案

您几乎回答你自己的问题的问题;)

You are almost answering your own question in the question ;)

请尝试使用:

android:launchMode="singleInstance"

虽然被警告,如果你正在做anythign像startActivityForResult - !你将永远不会得到结果

Be warned though, if you are doing anythign like startActivityForResult - you will never receive the result!

更新:

如果你想获得新的使用onNewIntent意图数据:

If you want to receive new intent data using onNewIntent:

public void onNewIntent(Intent intent)
{
    super.onNewIntent(intent);
    setIntent(intent);
}

当您使用getIntent(),以将其传递给onNewIntent新意图将改变原意的应用程序返回。

That will change the intent the application returns when you use getIntent() to the new intent which was passed to onNewIntent.

这篇关于Android的launchmode =" singleTask"不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆