Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; public class Main { public static boolean isAppRunningBackground(Context paramContext) { String pkgName = null; List<RunningAppProcessInfo> localList = null; if (paramContext != null) { pkgName = paramContext.getPackageName(); ActivityManager localActivityManager = (ActivityManager) paramContext.getSystemService("activity"); if (localActivityManager != null) { localList = localActivityManager.getRunningAppProcesses(); if ((localList == null) || (localList.size() <= 0)) { return false; } } } for (Iterator<RunningAppProcessInfo> localIterator = localList.iterator(); localIterator.hasNext();) { ActivityManager.RunningAppProcessInfo info = localIterator.next(); if (info.processName.equals(pkgName) && info.importance != 100) { return true; } } return false; } }