Recently in a small project, you need to get the top of the Activity stack and the App ProcessIt belongs to in real time.
According to the previous understanding, know that the Android API has an interface available
Public List < Activitymanager.runningtaskinfo > getrunningtasks (int maxnum)
You can get a list of tasks currently running on the system, using maxnum to limit the number you want to get (the most recently used first fetched).
When actually running the program, it is found that the current Activity stack top is not available in real time.
(using the Android L machine for debugging)
Reason:
At the start of Android L ,Google began restricting the use of the getrunningtasks interface.
By default, normal three-party apps (non-system apps cannot use the interface)
Previously, using this interface requires Android.permission.GET_TASKS
Even if you are developing a common application, you can use the getrunningtasks interface Whenever you declare the permission.
But starting from L , this way as well as abandonment.
The application must declare permissions to use this interface Android.permission.REAL_GET_TASKS
This permission is not open for three-party applications. (Applied in Manifest also has no effect)
The System application (with a system signature) can invoke this permission.
At the same time, consult the source of the interface in the Activitymanager , for ordinary three-party applications, should only allow the Eng version of debug use , and Google It is not recommended to use this interface in the core logic of your application.
If there is a problem using this interface on the Android LL version, you can refer to the above content.
The reason Google does this is because of security concerns, the development of the interface for a common application may result in user privacy disclosure.
Getrunningtasks interface for use on Android LL