is App Running Top - Android android.content.pm

Android examples for android.content.pm:App

Description

is App Running Top

Demo Code

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;

public class Main {

  public static boolean isAppRunningTop(Context context) {

    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = am.getRunningTasks(1);
    if (list.size() > 0) {
      String packageName = context.getPackageName();
      RunningTaskInfo topRunningTaskinfo = list.get(0);
      if (topRunningTaskinfo.topActivity.getPackageName().equals(packageName)) {
        return true;
      }/* w w w  .ja v  a 2s  .  c  om*/
    }

    return false;
  }

}

Related Tutorials