print Tasks Information - Android Android OS

Android examples for Android OS:Process

Description

print Tasks Information

Demo Code


//package com.java2s;
import java.util.List;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.util.Log;

public class Main {

    public static void printTasks(Context context, String logTag) {
        String packageName = context.getPackageName();
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> recentTasks = activityManager
                .getRunningTasks(Integer.MAX_VALUE);
        if (recentTasks != null && recentTasks.size() > 0) {
            int count = 0;
            for (RunningTaskInfo t : recentTasks) {
                String pack = t.baseActivity.getPackageName();
                if (pack.equals(packageName)) {
                    String s = "Task [" + (count++) + "] : " + "base ["
                            + t.baseActivity.getShortClassName()
                            + "] , top ["
                            + t.topActivity.getShortClassName()
                            + "] activityStack.size > " + t.numActivities;
                    Log.v(logTag, s);//from  w w w. ja  va 2s.c  o m
                }
            }

        }
    }
}

Related Tutorials