0

I want to implement the functionality of task switch button (device hardware button) in my application. Can any one have any idea how to show the same task list pragmatically? ::

Note I already know that there is a function from where you can get current tasks and can show them but I don't want this.

arodriguezdonaire
  • 5,396
  • 1
  • 26
  • 50
Ali Imran
  • 8,927
  • 3
  • 39
  • 50

1 Answers1

0

You can do this by using ActivityManager.RunningTaskInfo

ActivityManager has method getrunningtasks() and using that try to find a solution to your problem Activity manager seems to be the solution you are searching for.

  ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < tasks.size(); i++) {
    Log.d("Running task", "Running task: " + tasks.get(i).baseActivity.toShortString() + "\t\t ID: " + tasks.get(i).id);
}

also have a look at following thread See Android recent task executed by the user

note:

The method getRunningTasks(int maxNum), was deprecated in the API level 21(LOLLIPOP), for security reasons, the possibility of leaking personal information to third-party applications. (If you use this method to be aware that it will not be supported for future Android versions).

Community
  • 1
  • 1
King of Masses
  • 18,405
  • 4
  • 60
  • 77