-1

I'd want to get recent task list.

I use the following code, but when I try to get origActivity info, origActivity is always null:

ActivityManager activityManager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(8,0);

I want to know application label, package name and activity name of all activities of the list.

The only way to know these elements is to use origActivity from RecentTaskInfo but it is always null (I get a NullPOinterException).

The only information that I can get is the Activity id.

There is a way to know application label, package name and activity name of all recent task?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Meroelyth
  • 5,310
  • 9
  • 42
  • 52
  • Possible duplicate of [Get Recent and Running application list not processes](http://stackoverflow.com/questions/12376646/get-recent-and-running-application-list-not-processes) – Artificioo Mar 08 '16 at 13:51

3 Answers3

1

To get all the package name and class name , go with the base intent variable. The example below taken from getView() function from AdapterView.

final ActivityManager.RecentTaskInfo temp = this.getItem(position); 
final String packagename = temp.baseIntent.getComponent().getPackageName();
final String label = getPackageManager().getApplicationLabel(getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA))
hansip87
  • 11
  • 2
-1

I used this code to initialze acitivty manager

     activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

and why dont you use

        List<RunningAppProcessInfo> rpinfo= activityManager.getRunningAppProcesses();

from this u can get all the information you want and the list is sorted according to the recent task. Means latest used task is at the top to u can get as many recent task you want
And to get the application label

PackageManager pm=getApplicationContext().getPackageManager();  
ApplicationInfo ai;

try {
    ai=pm.getApplicationInfo(processName, 0);
    name=(String) pm.getApplicationLabel(ai);
}
Ali
  • 12,354
  • 9
  • 54
  • 83
  • Many thanks for the answer. I know getRunningTasks, but I want the recent task not the running. – Meroelyth Dec 16 '12 at 21:39
  • go through this http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks(int) – Gaurang Agarwal Dec 16 '12 at 21:50
  • "and the list is sorted according to the recent task" this is unfortunately not true. As stated out in the API, the ordering is not specified and a lot devices will *not* order the list with the recent at top. – JacksOnF1re Dec 16 '15 at 12:50
-1

you must hold this permission
GET_TASKS

Smile
  • 375
  • 1
  • 3
  • 13