use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.
the class ActivityTestMain method findDocTask.
ActivityManager.AppTask findDocTask() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasks = am.getAppTasks();
if (tasks != null) {
for (int i = 0; i < tasks.size(); i++) {
ActivityManager.AppTask task = tasks.get(i);
ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
if (recent.baseIntent != null && recent.baseIntent.getComponent().getClassName().equals(DocActivity.class.getCanonicalName())) {
return task;
}
}
}
return null;
}
use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.
the class ActivityTestMain method setExclude.
void setExclude(boolean exclude) {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasks = am.getAppTasks();
int taskId = getTaskId();
for (int i = 0; i < tasks.size(); i++) {
ActivityManager.AppTask task = tasks.get(i);
if (task.getTaskInfo().id == taskId) {
task.setExcludeFromRecents(exclude);
}
}
}
use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.
the class ActivityTestMain method addAppRecents.
void addAppRecents(int count) {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setComponent(new ComponentName(this, ActivityTestMain.class));
for (int i = 0; i < count; i++) {
ActivityManager.TaskDescription desc = new ActivityManager.TaskDescription();
desc.setLabel("Added #" + i);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
if ((i & 1) == 0) {
desc.setIcon(bitmap);
}
int taskId = am.addAppTask(this, intent, desc, bitmap);
Log.i(TAG, "Added new task id #" + taskId);
}
}
use of android.app.ActivityManager 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;
}
use of android.app.ActivityManager in project LshUtils by SenhLinsh.
the class AppUtils method isServiceRunning.
/**
* 检查服务是否正在运行
*/
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
//获取Activity管理器
ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
//获取运行中服务
List<RunningServiceInfo> services = manager.getRunningServices(1000);
String serviceName = service.getName();
for (RunningServiceInfo info : services) {
//获取每一条运行中的服务的类名并判断
String name = info.service.getClassName();
if (TextUtils.equals(serviceName, name)) {
return true;
}
}
return false;
}
Aggregations