1

I am writing an Android App recently and I create several activities using FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASKS.
And I want to get the info of these new tasks(as well as activities)by using getRunningTasks.
Also I want to set some unique identifiers for these tasks in order to manage them conveniently.
I have tried to use the description, but it can not be modified.Codes are as followed:

    ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfos = am.getRunningTasks(2);
    ActivityManager.RunningTaskInfo currentTaskInfo = taskInfos.get(0);
    am.getRunningTasks(2).get(0).description = "dfasdfsa";  
    Toast.makeText(this,am.getRunningTasks(2).get(0).description, 10).show();  

When the Toast shows, the value of description is still null.I seems I can not change it.
Please give me a solution to set a unique identifier for a task.
I really appreciate your help! :)

laosiaudi
  • 9
  • 2

1 Answers1

0

First, this is not the way to set your taskDescription. To set your taskDescription you need to use this method:

ActivityManager.TaskDescription taskDescription = 
            new  ActivityManager.TaskDescription("label");
this.setTaskDescription(taskDescription);

This is a simple constructor of TaskDescription, for more constructors, check: https://developer.android.com/reference/android/app/ActivityManager.TaskDescription You can set more description variables there.

Secondly, am.getRunningTasks(2).get(0).description this was depricated a while ago, however, some vendors even didn't allow it to be used before that.

To check your description if it is set to your value, for example, you can run

adb shell dumpsys activity activities

However, if you really want to check it in runtime, it is available after API 21:

final ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.AppTask> appTasks = am.getAppTasks();
for(ActivityManager.AppTask task : appTasks) {
       Log.d("TaskDesc", "taskDesc: " + task.getTaskInfo().taskDescription);
}
Caner Kaya
  • 52
  • 1
  • 6