gpt4 book ai didi

android - 有没有办法动态添加或删除 Activity 类别?

转载 作者:行者123 更新时间:2023-11-29 01:25:03 25 4
gpt4 key购买 nike

我正在使用 LauncherActivity 来动态决定我想在列表中显示哪个 Activity 。

@Override
protected Intent getTargetIntent() {
targetIntent.addCategory(xxx_category1);
targetIntent.addCategory(xxx_category2);
.........
targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return targetIntent;
}

LauncherActivity 使用具有特定类别的 Intent 来过滤掉那些不需要的 Activity 。然而,这些类别是在 xml 中预定义的, Activity 必须适合所有类别(不是“或”,而是“和”所有类别),使其符合使 LauncherActivity 灵 active 降低的条件。

所以我想知道有没有办法动态添加或删除 Activity 的类别?非常感谢!

最佳答案

Activity 别名有助于满足动态“编辑” Activity 的需要。通过使用别名而不是您的实际 Activity ,您可以创建具有多种配置的多个别名。通过为您要提供的每个可能配置设置别名,您可以根据需要启用/禁用别名,从而从系统应用程序启动器等各种 View 中添加/删除图标。

Activity 别名

The alias presents the target activity as a independent entity. It can have its own set of intent filters, and they, rather than the intent filters on the target activity itself, determine which intents can activate the target through the alias and how the system treats the alias.

在您的情况下,听起来您想要为每个要点击的类别配置设置一个别名。我相信在这种情况下,别名应该能很好地工作。我还注意到动态配置,因为我不确定我是否完全理解您的问题,因此如果我误解了它可能会更加清晰。

http://developer.android.com/guide/topics/manifest/activity-alias-element.html

编辑别名

Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.

http://developer.android.com/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting(android.content.ComponentName, int, int)

关于android - 有没有办法动态添加或删除 Activity 类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34522153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com