Android
中ActivityManager类似于Windows
下的任务管理器,能得到正在运行程序的内容等信息
- List<ActivityManager.RunningServiceInfo> getRunningServices(int maxNum)
Return a list of the services that are currently running.
这个maxNum是指返回的这个集合的最大值
可以利用ActivityManager
去判断当前某个服务是否正在运行。 -
List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses()
Returns a list of application processes that are running on the device. -
List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum, int flags)
得到最近使用的程序,集合中第一个元素是刚才正在使用的 -
Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids)
Return information about the memory usage of one or more processes.
可以通过某个进程的id得到进程的内存使用信息,然后通过这个内存信息能够得到每个程序使用的内存大小MemoryInfo中的方法
int getTotalPrivateDirty()
Return total private dirty memory usage in kB得到占用内存的大小,单位是kb - 一键清理
杀死进程需要权限杀死进程就是使用ActivityManager的killBackgroundProcess方法
public void killBackgroundProcesses(String packageName)
- 获取内存可用大小