APIS related to the internal status of the Android system:
Activitymanager:
Activitymanager = (activitymanager) This. getsystemservice (activity_service)
What information is this bit:
Configurationinfo = activitymanager. getdeviceconfigurationinfo ();
Obtain the memory status of a process:
Debug. memoryinfo [] processmemoryinfo = activitymanager. getprocessmemoryinfo (processids );
Obtain information about the currently running service:
List <runningserviceinfo> runningserviceinfos = activitymanager. getrunningservices (maxvalue );
Obtain information about the currently running task:
List <runningtaskinfo> runningtaskinfos = activitymanager. getrunningtasks (maxvalue );
Among them, the topactivity of runningtaskinfos is the active activity of the current task.
In the task queue returned by getrunningtasks (), the system sorts the tasks according to their activity level, and the more active the tasks are. The first is the active task.
/**
* Checks whether an activityupdate is at the top of the stack of the current task.
*/
Public
Boolean istopactivy (string comment name ){
Activitymanager manager = (activitymanager) Context. getsystemservice (activity_service );
List <runningtaskinfo> runningtaskinfos = manager. getrunningtasks (1 );
String cmpnametemp = NULL;
If (null! = Runningtaskinfos ){
Cmpnametemp = (runningtaskinfos. Get (0). topactivity). tostring );
Log. E ("cmpname", "cmpname:" + cmpname );
}
If (null = cmpnametemp) return false;
Return cmpnametemp. Equals (parameter name );
}
Finally, add the required permissions to the application:
<Uses-Permission Android: Name = "android. Permission. get_tasks"/>