开发者

Android: reading Running + Paused State Tasks list

开发者 https://www.devze.com 2023-04-13 05:29 出处:网络
I want to read package name of all running applications. Here is my Code to read Running applications:

I want to read package name of all running applications.

Here is my Code to read Running applications:

public static getRunningTasks(final Context context) {
    final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningTaskInfo> task = manager.getRunningTasks(Integer.MAX_VALUE);
    for (final RunningTaskInfo info : task) {
        System.out.println("base activity "+info.baseActivity.getPackageName());
    }
}

The output :

10-13 09:08:24.348: INFO/System.out(3295): base activity com.gt.mytest
10-13 09:08:24.348: INFO/System.out(3295): base activity com.android.launcher

But this is showing only the Application wi开发者_开发知识库th Running State in LifeCycle.

How can i read all(including Running State and Paused State) tasks?


I found what's wrong, That was my silly mistake

I used

 List<RunningAppProcessInfo> service = manager.getRunningAppProcesses();

instead of

List<RunningTaskInfo> task = manager.getRunningTasks(Integer.MAX_VALUE); 

and got solution. :D

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号