Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:Main.java

public static String getRunningActivityName(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    String runningActivity = activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
    return runningActivity;
}

From source file:Main.java

public static void killProcess(Context ctx, String pkgName) {
    ActivityManager actManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    // version 1.5 - 2.1
    if (android.os.Build.VERSION.SDK_INT <= 7) {
        actManager.restartPackage(pkgName);
    }/*ww w .  j  a v  a 2 s.c  o m*/
    // version 2.2+
    else {
        actManager.killBackgroundProcesses(pkgName);
    }
}

From source file:Main.java

public static int getActivityIconSize(Context c) {
    return 2 * ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getLauncherLargeIconSize();
}

From source file:Main.java

private static String getCurProcessName(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
        if (appProcess.pid == android.os.Process.myPid()) {
            return appProcess.processName;
        }//from   www . ja v a  2s  .  c  o m
    }
    return "";
}

From source file:Main.java

public static int getRunningProcess(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> lists = am.getRunningAppProcesses();
    return lists.size();
}

From source file:Main.java

public static String getRunningAppNameByPID(Context context, int pid) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
        if (processInfo.pid == pid)
            return processInfo.processName;
    }//from  ww  w .  j a  v  a2 s. c o m

    return null;
}

From source file:Main.java

public static boolean isSingleActivity(Context ctx) {
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
    return tasks.get(0).numRunning == 1;
}

From source file:Main.java

public static int getCountProcesses(Context mContext) {
    int iTemp = 0;
    ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    iTemp = manager.getRunningAppProcesses().size();
    return iTemp;
}

From source file:Main.java

public static String getTopActName(Context ctx) {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
    String clsName = cn.getClassName();
    return clsName;
}

From source file:Main.java

public static boolean isStackResumed(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
    ActivityManager.RunningTaskInfo runningTaskInfo = runningTaskInfos.get(0);
    return runningTaskInfo.numActivities > 1;
}