Android ActivityManager
Android About 1,251 words获取Activity管理器
//获取活动管理器
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
-
获取正在运行的服务,传0参数表示获取的服务的最大数
List<RunningServiceInfo> runningServices = am.getRunningServices(1000); for (RunningServiceInfo runningServiceInfo : runningServices) { String className = runningServiceInfo.service.getClassName(); }
-
2.获取正在运行的进程
List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses(); for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
}
- 获取正在运行的任务栈
传1参数表示最多可以获取多少个正在运行的任务栈
```java
List<RunningTaskInfo> runningTasks = am.getRunningTasks(1);
for (RunningTaskInfo runningTaskInfo : runningTasks) {
//获取最底部的activity
ComponentName baseActivity = runningTaskInfo.baseActivity;
//获取最顶部的activity
//ComponentName topActivity = runningTaskInfo.topActivity;
String packageName = baseActivity.getPackageName();
}
-
获取系统当前的内存
保存到MemoryInfoMemoryInfo outInfo = new MemoryInfo(); am.getMemoryInfo(outInfo);
-
杀死后台进程
List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses(); for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { am.killBackgroundProcesses(runningAppProcessInfo.processName); }
Views: 3,986 · Posted: 2019-04-13
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...