Java tutorial
//package com.java2s; import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import java.util.List; public class Main { public static boolean isApplicationBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; } }