在不使用android:launchMode ="singleTask"的情况下在新任务中打开android活动. [英] open android activity in new task without using android:launchMode="singleTask"

查看:60
本文介绍了在不使用android:launchMode ="singleTask"的情况下在新任务中打开android活动.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个浏览器应用程序,该应用程序具有主要活动,可以响应以下意图:

I've created a browser application with main activity which response to the following intents:

 <intent-filter> 
       <data android:scheme="http"/>
       <data android:scheme="https"/>
       <category android:name="android.intent.category.DEFAULT"/>
       <category android:name="android.intent.category.BROWSABLE"/>
       <action android:name="android.intent.action.VIEW"/>
 </intent-filter>

如果我选择我的应用程序,则在从其他任务(gmail,sms)的url单击上,活动在与调用任务相同的任务中打开. 当我选择其他浏览器(Mozila firefox,chrome,dolphine)时,它们将打开不同的任务.

On url click from other task (gmail, sms) if i choose my application, the activity is open in the same task as the calling task. When I choose different browser (Mozila firefox, chrome, dolphine) they are opening in different task.

在其他浏览器清单上,我发现没有人使用 android:launchMode ="singleTask" .

Looking on other browsers manifest, I see that no one using android:launchMode="singleTask".

我不想使用单个任务标志,因为它不被google推荐,这也会给我带来其他麻烦.

I don't want to use single task flag since it is not recommended by google and also makes me other prolems.

我试图了解其他浏览器是如何做到的,但没有弄清楚.

I tried to understand how does other browsers do it but didn't figure it out.

有什么想法吗?有没有其他方法可以在不使用singleTask标志的情况下打开我在其他任务中的活动?

any ideas? is there other way to open my activity in different task without using singleTask flag?

推荐答案

您正在尝试弯曲规则",而对于不使用.

You're trying to "bend the rules" a little, and you're not clear enough on what you're trying to avoid by not using android:launchMode="singleTask".

因此,我建议研究以下任一情况:

So I would suggest researching into either:

  1. 创建一个Service并让该Service监听意图过滤器.然后让此Service打开Activity,并正确设置Activity的相似性以匹配Service的相似性.这样可以解决亲和力未正确绑定Activity的问题.

  1. Creating a Service and having that Service listen to the intent filter. Then having this Service open your Activity, and having the Activity's affinity set correctly to match the Service's. This would allow you to get over the issue where affinity is not binding the Activity correctly.

静默的Activity启动新的Activity并退出.静默的Activity将在新堆栈中启动(而不是在单任务模式下),并且在启动您实际需要的Activity时会自行关闭.

Having a silent Activity starting a new Activity and quiting. The silent Activity would start in a new stack (not in a singletask mode), and would shut itself down upon starting the Activity you actually need.

这篇关于在不使用android:launchMode ="singleTask"的情况下在新任务中打开android活动.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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