Android5.0失效API统计及解决方法

Android 5 API Changes – getAppTasks( )

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…

… 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( ).

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.




more: http://www.intertech.com/Blog/android-5-api-changes-getapptasks/#ixzz3WcAQbPxT 
Follow us: @IntertechInc on Twitter | Intertech on Facebook
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值