Here you can find the source of isApplicationBroughtToBackground(Context context)
public static boolean isApplicationBroughtToBackground(Context context)
//package com.java2s; import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.ComponentName; import android.content.Context; public class Main { public static boolean isApplicationBroughtToBackground(Context context) { ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (tasks != null && !tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals( context.getPackageName())) { return true; }//w ww .jav a 2s. com } return false; } }