Android examples for Activity:Activity Status
get Running Activity Count
//package com.java2s; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.Context; import java.util.Iterator; import java.util.List; public class Main { public static int getRunningActivityCount(Context context) { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskList = activityManager .getRunningTasks(1);/* ww w .j a va 2s . c o m*/ int count = 0; for (Iterator<RunningTaskInfo> iterator = runningTaskList .iterator(); iterator.hasNext();) { RunningTaskInfo info = (RunningTaskInfo) iterator.next(); if (info.baseActivity.getPackageName().equals( context.getPackageName())) { count = info.numActivities; } } return count; } }