651.288.7000 info@intertech.com

By now, you are aware that Android 5 (called Lollipop) was released (see here) in November.  While the number of devices available to run (let alone actually running Lollipop) are few at this time, we should all start to see Lollipop on our devices in the coming year.

Per my post earlier this summer (see here), along with several recent bulletins (here is one from Google), this is a “major” release under almost anyone’s definition – full of all sorts of new functionality.  In the coming weeks, I hope to review and provide you some tutorials on the new features.

However, one of my pleasures in looking at new software releases is to also inspect the changes (versus new features) in a release.  What has been modified/fixed and why?  I find that the health and welfare of a platform is sometimes better suggested by the changes than by the new features of a release.

In Lollipop, one of the changes (you can find a list here) is the deprecation of ActivityManager.getRecentTasks( ) and the addition of its replacement ActivityManager.getAppTasks( ).  This change was made in order “to improve user privacy”  – an issue that has become very important as Android and all mobile platforms have had to react to user expectations with regard to security and privacy concerns.

Used Previously – getRecentTasks( )

In prior versions, the getRecentTasks( ) method on an ActivityManager instance provided a list of user initiated tasks (via ActivityManager.RecentTaskInfo objects) recently launched giving them in order of most recently launched first.  This list is inclusive of all tasks regardless of whether the tasks were associated to an application or not.

So, for example, the following code…

private void listTasks() throws PackageManager.NameNotFoundException {
  List<ActivityManager.RecentTaskInfo> tasks = mgr.getRecentTasks(20, 0);
  String packagename;
  String label;
  for(ActivityManager.RecentTaskInfo task: tasks){
    packagename = task.baseIntent.getComponent().getPackageName();
    label = getPackageManager().getApplicationLabel(getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA)).toString();
    Log.v(TAG,packagename + ":" + label);
    }
}

… might produce the following output when run on a prior-to-Lollipop-device or AVD.

Recent Tasks

Note that the list included my app (TestGetTasks) as well as a lot of other 3rd party apps I brought up just prior to launching my app.  In other words, any app (prior to Android 5) had access to information that many users may not have wanted them to have.

[Side note, the use of getRecentTasks( ) does require the manifest include a user permission request for android.permission.GET_TASKS.  However, as we know, users are not always good about carefully reading through the app permission requests before allowing the app to be installed and used.]

Used Now in Android 5 – getRecentTasks( )

In Android 5, this method has been altered to protect personal information.  In Android 5, this method will return “a small subset of its data: at least the caller’s own tasks, and possibly some other tasks such as home that are known to not be sensitive” (see the documentation here).  The same code above would produce the following output when run on a Lollipop device or AVD:

Recent Tasks in Android 5

In fact, the getRecentTasks( ) method is deprecated as of Android 5.  While it is still available for backward compatibility, Android considers this method “no longer available to third party applications.”  In its place, developers are to use getAppTasks( ).

Added in Android 5 – getAppTasks( )

Here is the similar, but new getAppTasks( ) method being used in code that replaces getRecentTasks( ).

private void listTasks() throws PackageManager.NameNotFoundException {
  ActivityManager mgr = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
  List<ActivityManager.AppTask>  tasks = mgr.getAppTasks();
  String packagename;
  String label;
  for (ActivityManager.AppTask task: tasks){
    packagename = task.getTaskInfo().baseIntent.getComponent().getPackageName();
    label = getPackageManager().getApplicationLabel(getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA)).toString();
    Log.v(TAG,packagename + ":" + label);
  }
}

Importantly, note that the getAppTasks( ) method does return a different list of objects – one containing AppTask objects versus the RecentTaskInfo objects.  Now, this replacement method returns only “the list of tasks associated with the calling application.”

App Tasks

Wrap up

Change is good.  In this case, change is important to protect more of Android users’ privacy.  Stay tuned to this blog over the coming months to learn more about Android 5 features.  In fact, I am attending and speaking at the AnDevCon this week and hope to learn more about Android 5 myself.  Hope you can attend.

ADC-SF2014-SpeakerBadgeIf you cannot attend, check out this post for my presentation.