Ответ 1
Вы не можете.
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 <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
.