Alternative to getRunningTasks in Android L

The system statistics api evoked in your question is also presented here and the detailed API is here. As far as I can see this API won’t allow you to get the current top activity.

i.e. you have the ability to receive UsageEvent with the type MOVE_TO_FOREGROUND by using UsageStatsManager.queryEvents but according javadoc :

The last few minutes of the event log will be truncated to prevent abuse by applications.

So it is really an API to get statistics, not to get realtime information. (note that the now deprecated getRunningTasks() was neither intended to retrieve realtime data : javadoc)

On the other hand, if you are only interested in top activity of your own app: you can use getAppTasks() returning a List<AppTask> where you can get the RecentTaskInfo with getTaskInfo


EDIT : another approach is provided here.

It is based on UsageStats and UsageStats.getLastTimeUsed(). Drawback : it requires additional permission and gives you only the package name -not the activity-, but it gives you real time data.

Leave a Comment