首页 > 代码库 > android 获取前台进程

android 获取前台进程

String getTopActivity()
{
ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

if(runningTaskInfos != null)
{
mRunningCount = runningTaskInfos.get(0).numRunning;
return (runningTaskInfos.get(0).topActivity).toString();
}
else
return null ;
}

android 获取前台进程