android 获取前台进程

时间:2021-02-21 18:13:20

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 ;
}