How to get all the tasks that are currently running

I want to get all the tasks that are performed in android.I discovered getRunningTasks in the ActivityManager, but from android-5.0 getRunningTasks may not complete all the tasks (in my case it gives the main screen and my application).

Also, is it possible to find the task that the user is currently interacting with?

Any help would be greatly appreciated.

Thank.

Change . I am using the following code snippet. But it gives me only one process (this is my application). Even if I open other applications, it does not show them. I run this One Plus 2.

@Override
    protected void onHandleIntent(Intent intent) {
        new Timer().scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                getRunningApps();
            }
        }, 0, 1000);//put here time 1000 milliseconds=1 second
    }

    public void getRunningApps() {
        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningAppProcessInfo> recentTasks = activityManager.getRunningAppProcesses();

        for (int i = 0; i < recentTasks.size(); i++)
        {
            Log.d("Executed app", "Application executed : " +recentTasks.get(i).pkgList[0]+ "\t\t ID: "+recentTasks.get(i).pid+"");
        }
    }
+4
source share
4 answers

getRunningAppProcesses, RunningAppProcessInfo, . , , importance, IMPORTANCE_FOREGROUND, , !

:

getRunningAppProcesses

RunningAppProcessInfo

IMPORTANCE_FOREGROUND

, :)

+2

, Android .

0

I believe getRecentTasks and getRunningTask are deprecated from API 21. I'm not sure what you are trying to achieve, maybe you should try getRunningAppProcess . which give a similar result.

-1
source

Use it codeHis work for me. Do not forget to use ListViewin your file Xml.

ListView listView = (ListView) findViewById(R.id.listview);
        ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> 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<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
        listView.setAdapter(adapter);  
-1
source

All Articles