How to get all the tasks that are running currently

后端 未结 4 484
轮回少年
轮回少年 2021-01-18 12:43

I want to get all the tasks that are running in android.I found getRunningTasks in ActivityManager but from android-5.0 the getRunningTasks may not give all the tasks (in my

4条回答
  •  粉色の甜心
    2021-01-18 13:39

    Use this code Its works for me. Dont forgot to use ListView in your Xml File.

    ListView listView = (ListView) findViewById(R.id.listview);
            ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
            List procInfos = actvityManager.getRunningAppProcesses();
            String[] values = new String[procInfos.size()];
            final String packageName = "my.application.package";
            PackageManager packageManager = getApplicationContext().getPackageManager();
            for (int i = 0; i < procInfos.size(); i++) {
                values[i] = procInfos.get(i).processName;
            }
            ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);
            listView.setAdapter(adapter);  
    

提交回复
热议问题