0

I have an app that is using the topActivity call to timeout after a period of inactivity between apps, which worked fine on android 4.x but since the update to 5.x this has stopped working.

The full call is

ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();

Has anyone experienced this before or have a solution? There are no errors it is just not returning what is expected.

Note: This is not for a commercial app, this is for a very limited, managed distribution.

Cob50nm
  • 911
  • 2
  • 9
  • 27

1 Answers1

0

Quoting the documentation for getRunningTasks():

This method was deprecated in API level 21.

As of LOLLIPOP, this method is no longer available to third party applications: the introduction of document-centric recents means it can leak person information to the caller. For backwards compatibility, it will still 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.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks. does deprecation in android not generally mean that its is not recommended and not guaranteed stable, but not that it wont work. – Cob50nm May 28 '15 at 14:35
  • @Cob50nm: Yes, in general, "deprecated" means that Google would recommend that you use something else, but that the deprecated classes or methods still work. Occasionally, as in this case, "deprecated" more quickly eliminates functionality, particularly where privacy and security are concerned. – CommonsWare May 28 '15 at 14:42
  • again thank you, fully understandable why they did it, just annoying as it means I need to find a workaround now. – Cob50nm May 28 '15 at 14:58