设置“任务关联性”以编程方式

发布于 2024-11-09 07:04:08 字数 158 浏览 5 评论 0原文

有没有办法以编程方式设置“任务亲和力”?我的意思是像一些意图标志或什么?我在 Android 文档中没有发现任何关于此的可能性。

在 AndroidManifest.xml 中使用 android:taskAffinity 以静态方式设置亲和力不符合我的需求。

is there a way to set the "task affinity" programmatically? I mean like with some Intent flag or sth? I didn't find anything about this being possible in the Android docs.

Setting the affinity in a static way in the AndroidManifest.xml with android:taskAffinity does not suit my needs.

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

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

发布评论

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

评论(2

[浮城] 2024-11-16 07:04:08

你不能。

taskAffinityActivityInfo 包含,它是 Activity 的成员。

Activity 源代码

public class Activity extends ContextThemeWrapper
    ...
    ... {
    // set by the thread after the constructor and before 
    // onCreate(Bundle savedInstanceState) is called.

    @UnsupportedAppUsage
    /*package*/ ActivityInfo mActivityInfo;
 }

并且ActivityInfo具有taskAffinity。

ActivityInfo 源代码< /a>

/**
 * Information you can retrieve about a particular application
 * activity or receiver. This corresponds to information collected
 * from the AndroidManifest.xml's <activity> and
 * <receiver> tags.
 */
public class ActivityInfo extends ComponentInfo implements Parcelable {

   /**
    * The affinity this activity has for another task in the system.  The
    * string here is the name of the task, often the package name of the
    * overall package.  If null, the activity has no affinity.  Set from the
    * {@link android.R.attr#taskAffinity} attribute.
    */
    public String taskAffinity;

根据源码注释,taskAffinity的信息是从AndroidManifest.xml中收集的。并且没有公共方法来设置mActivityInfo.taskAffinity

You cannot.

taskAffinity is contained by ActivityInfo, which is member of Activity.

Source code of Activity

public class Activity extends ContextThemeWrapper
    ...
    ... {
    // set by the thread after the constructor and before 
    // onCreate(Bundle savedInstanceState) is called.

    @UnsupportedAppUsage
    /*package*/ ActivityInfo mActivityInfo;
 }

And ActivityInfo has taskAffinity.

Source code of ActivityInfo

/**
 * Information you can retrieve about a particular application
 * activity or receiver. This corresponds to information collected
 * from the AndroidManifest.xml's <activity> and
 * <receiver> tags.
 */
public class ActivityInfo extends ComponentInfo implements Parcelable {

   /**
    * The affinity this activity has for another task in the system.  The
    * string here is the name of the task, often the package name of the
    * overall package.  If null, the activity has no affinity.  Set from the
    * {@link android.R.attr#taskAffinity} attribute.
    */
    public String taskAffinity;

According to the comment of source code, information of taskAffinity is collected from AndroidManifest.xml. And there is no public method to set mActivityInfo.taskAffinity.

久夏青 2024-11-16 07:04:08

使用这个方法:

finishAffinity();

Use this method :

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