use of android.app.ActivityManager.RunningServiceInfo in project carat by amplab.
the class SamplingLibrary method getRunningAppInfo.
public static List<ProcessInfo> getRunningAppInfo(Context c) {
List<RunningAppProcessInfo> runningProcs = getRunningProcessInfo(c);
List<RunningServiceInfo> runningServices = getRunningServiceInfo(c);
List<ProcessInfo> l = new ArrayList<ProcessInfo>();
if (runningProcs != null) {
for (RunningAppProcessInfo pi : runningProcs) {
if (pi == null)
continue;
ProcessInfo item = new ProcessInfo();
item.setImportance(CaratApplication.importanceString(pi.importance));
item.setPId(pi.pid);
item.setPName(pi.processName);
l.add(item);
}
}
if (runningServices != null) {
for (RunningServiceInfo pi : runningServices) {
if (pi == null)
continue;
ProcessInfo item = new ProcessInfo();
item.setImportance(pi.foreground ? "Foreground app" : "Service");
item.setPId(pi.pid);
item.setPName(pi.clientPackage);
l.add(item);
}
}
return l;
}
use of android.app.ActivityManager.RunningServiceInfo in project Lazy by l123456789jy.
the class AppUtils method gc.
/**
* 清理后台进程与服务
*
* @param context 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context context) {
long i = getDeviceUsableMemory(context);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null) {
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
}
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null) {
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
if (DEBUG) {
}
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
}
}
}
}
}
if (DEBUG) {
}
return count;
}
use of android.app.ActivityManager.RunningServiceInfo in project Lazy by l123456789jy.
the class AppUtils method isServiceRunning.
/**
* 检测服务是否运行
*
* @param context 上下文
* @param className 类名
* @return 是否运行的状态
*/
public static boolean isServiceRunning(Context context, String className) {
boolean isRunning = false;
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
for (RunningServiceInfo si : servicesList) {
if (className.equals(si.service.getClassName())) {
isRunning = true;
}
}
return isRunning;
}
use of android.app.ActivityManager.RunningServiceInfo in project KJFrameForAndroid by kymjs.
the class SystemTool method gc.
/**
* 清理后台进程与服务
*
* @param cxt
* 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context cxt) {
long i = getDeviceUsableMemory(cxt);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null)
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
continue;
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null)
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
KJLoger.debug("======正在杀死包名:" + pkgName);
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
continue;
}
}
}
}
KJLoger.debug("清理了" + (getDeviceUsableMemory(cxt) - i) + "M内存");
return count;
}
use of android.app.ActivityManager.RunningServiceInfo in project LshUtils by SenhLinsh.
the class AppUtils method gc.
/**
* 清理后台进程与服务
*
* @return 被清理的数量
*/
public static int gc(Context context) {
long i = getDeviceUsableMemory(context);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null) {
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid())
continue;
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
}
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null) {
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
if (DEBUG) {
}
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
}
}
}
}
}
if (DEBUG) {
}
return count;
}
Aggregations