Java tutorial
//package com.java2s; import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; import android.text.TextUtils; public class Main { private static Context mContext = null; public static boolean isBackGround() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses(); for (RunningAppProcessInfo info : processInfos) { if (TextUtils.equals(info.processName, mContext.getPackageName()) && info.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) { return true; } } return false; } }