Android任务关联性问题与指定活动

发布于 2024-11-16 02:51:44 字数 631 浏览 0 评论 0原文

我在这里处理一个奇怪的问题。

基本上,我有一个应用程序(由另一位开发人员制作),其活动将其 taskAffinity 指定为“”,将 launchMode 指定为“singleTask”。

当手机收到通知时,我会在应用程序中启动带有 FLAG_ACTIVITY_NEW_TASK 标志的活动。

如果任务存在,我希望我的活动与其他应用程序具有任务关联性。

当我执行 dumpsys Activity 时,我看到其他开发人员应用程序 TaskRecord 是:

aj.streetPhone.app/.ViewActivity

但是,在我的活动清单中,我指定了 aj.streetphone.app ,它似乎没有添加我对该应用程序任务的活动。我尝试了另一个包名称,它似乎有效。该问题可能与任务名称包含活动而不仅仅是包名称(默认)有关。

我基本上在使用“/”时遇到问题,因为清单不接受它。

android:taskAffinity="aj.streetPhone.app/.ViewActivity" <--- does not work!

我尝试转义由 unicode 添加的“/”,一切。请帮忙!

有什么想法吗?

I am dealing with a strange issue here.

Basically, I have one application (made by another developer) that has an activity that specifies its taskAffinity to "" and its launchMode to "singleTask".

When the phone receives a notification, I launch an activity in my application with FLAG_ACTIVITY_NEW_TASK flag.

I would like my activity to have a taskAffinity for that other application if the task exists.

When I do dumpsys activity I see that the other developers application TaskRecord is:

aj.streetPhone.app/.ViewActivity

However, in my manifest on my activity I specify aj.streetphone.app it does not seem to add my activity to that applications task. I have tried another package name and it seems to be working. The problem perhaps has to do with the fact that the task name includes the activity, not just the package name (the default).

I am basically having a problem to use the '/' because the manifest does not accept it.

android:taskAffinity="aj.streetPhone.app/.ViewActivity" <--- does not work!

I have tried escaping the '/', added by unicode, everything. Please help!

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2024-11-23 02:51:44

任务关联性(以及权限、进程、共享用户 ID,以及
操作等)不受应用程序包名称限定。他们是一个
单字符串,很多内容必须是全局唯一的。仅添加“.foo”并不
使其独一无二,因为另一个应用程序可能有一个包名称
您自己的较短或较长的版本,也可以提出相同的名称。
因此,对于亲缘关系和进程,您可以在名称中使用“:”前缀
将其附加到您自己的包名称中并创建一个有保证的名称
您的包裹是独一无二的。

因此,您必须为您的任务亲和力使用唯一的字符串。

Task affinities (and permissions, and processes, and shared user IDs, and
actions, etc etc) are NOT qualified by the app package name. They are a
single string, much must be globally unique. Just adding a ".foo" does not
make it unique because another app could have a package name that is a
shorter or longer version of your own and also come up with the same name.
So for affinities and processes, you can use a ":" prefix in the name to
append it to your own package name and create a name that is guaranteed
unique for your package.

So you have to use a unique string for your task affinity.

玩世 2024-11-23 02:51:44

/ 确实无效。

除非它以某种方式缩写(快速查看我自己的应用程序的 dumpsys Activity 似乎表明事实并非如此),否则您的 Activity 的全名是 aj.streetPhone.app.ViewActivity< /代码>。但是,如果您想将包名称添加到 taskAffinity 前面,您只需使用冒号即可,例如 :myAffinity。也就是说,taskAffinity 并不意味着是活动的名称!

据我了解,taskAffinity旨在控制活动属于哪个“任务”。虽然我无法评论为什么您会尝试将 Activity 粘到另一个应用程序的任务中,但您可能需要清除关联性以指示该 Activity 可以位于任何任务中;虽然我还没有尝试过,但我想这会导致,例如,后退按钮返回到用户之前进行的任何活动,而不是返回到应用程序中最后活动的任何活动(您的任务)。

更多信息(仅供参考,这是 chemalarrea 引用但未注明出处的信息):
https://groups.google.com/forum/?fromgroups =#!topic/android-developers/wKwnV1k_96A

文档:
https://developer.android.com/guide/topics/manifest /activity-element.html#aff

The / is indeed invalid.

Unless it's been abbreviated in some way (a quick look at dumpsys activity for my own app seems to show that it isn't) your activity's full name is aj.streetPhone.app.ViewActivity. However, if you want to prepend your package name to the taskAffinity you can simply use a colon, e.g. :myAffinity. That said, the taskAffinity is not meant to be the activity's name!

As I understand it, taskAffinity is meant to control which "task" an activity belongs to. While I can't comment on why you'd try to stick an activity to another app's task, you may want to clear the affinity to indicate the activity can be in any task; although I haven't tried it I imagine this would result in, for example, the back button leading back to whatever activity the user was on before rather than leading back to whatever activity was last active in your app (your task).

More info (which, FYI, is where chemalarrea was quoting from without giving credit):
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/wKwnV1k_96A

Documentation:
https://developer.android.com/guide/topics/manifest/activity-element.html#aff

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文