2012-03-16 48 views

回答

10
ActivityManager m = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
    List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10); 
    Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator(); 
    while(itr.hasNext()) 
    { 
     RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next(); 
     int id = runningTaskInfo.id; 
     CharSequence desc= runningTaskInfo.description; 
     String topActivity = runningTaskInfo.topActivity.getShortClassName(); 
     int numOfActivities = runningTaskInfo.numActivities; 
    } 

注:您必須指定清單文件android.permission.GET_TASKS權限。

+2

由於Lolipop轉向以文檔爲中心的任務管理,可能會泄露個人信息,因此該方法已被Lolipop棄用。 – joecks 2015-01-25 12:12:38

相關問題