有没有办法以编程方式设置“任务亲和力”?我的意思是像一些意图标志或某事?我在 Android 文档中没有找到任何关于这可能的信息。
在 AndroidManifest.xml 中以静态方式设置亲和力android:taskAffinity
不适合我的需要。
你不能。
taskAffinity
被 包含ActivityInfo
,它是 的成员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。
/**
* 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
。
使用此方法:
finishAffinity();