android源码学习:ActivityManager类全理解

android源码学习:ActivityManager类全理解android.app下有个ActivityManager类,给类的作用,官方的解释是:这个类提供有关、交互、activities,services和包含process的信息。这个类中的许多方法都是为了调试或信息的目的,它们不应该被用来影响应用程序的运行时行为,这些方法在方法级文档中被调用。大多数应用程序开发人员不应该使用这个类,大多数的方法都是专门用例的。然而,一些方法更广泛地适

大家好,又见面了,我是你们的朋友全栈君。

android.app下有个ActivityManager类,该类的作用官方的解释是:
这个类提供有关、交互、 activities, services和包含process的信息。
这个类中的许多方法都是为了调试或信息的目的,它们不应该被用来影响应用程序的运行时行为,这些方法在方法级文档中被调用。
大多数应用程序开发人员不应该使用这个类,大多数的方法都是专门用例的。然而,一些方法更广泛地适用。例如,isLowRamDevice()允许您的应用程序检测它是否在低内存设备上运行,并相应的执行。clearApplicationUserData()用于具有重新设置数据功能的应用程序。

在一些特殊的用例中,应用程序可以与Task stack交互,应用程序可以使用该内部类的ActivityManager.AppTask和ActivityManager.RecentTaskInfo但是,一般来说,这个类中的方法只用于测试和调试。

内部类 解释
ActivityManager.AppTask 用于控制应用程序的任务
ActivityManager.MemoryInfo getMemoryInfo(ActivityManager.MemoryInfo)方法获取可用内存
ActivityManager.ProcessErrorStateInfo 您可以检索任何在错误条件下的进程的信息。
ActivityManager.RecentTaskInfo 您可以检索用户最近启动或访问的任务的信息。
ActivityManager.RunningAppProcessInfo 您可以检索关于正在运行的进程的信息。
ActivityManager.RunningServiceInfo 您可以检索当前系统中正在运行的特定服务的信息。
ActivityManager.RunningTaskInfo 您可以检索当前正在系统中“运行”的特定任务的信息。
ActivityManager.TaskDescription 您可以在最近的任务列表中设置和检索关于当前活动的信息。
方法 返回值 解释
addAppTask(Activity activity, Intent intent, ActivityManager.TaskDescription description, Bitmap thumbnail) int 添加一个ActivityManager.AppTask
clearApplicationUserData() boolean 允许应用程序从磁盘上删除自己的数据。
clearWatchHeapLimit() 清除之前由setWatchHeapLimit(long)设置的Watch Heap限制。
dumpPackageState(FileDescriptor fd, String packageName) 执行与给定的应用程序包名相关联的各种状态的系统转储。
getAppTaskThumbnailSize() Size 返回用于当前 ActivityManager.AppTask缩略图的当前设计尺寸,用于addAppTask(Activity, Intent, ActivityManager.TaskDescription, Bitmap)
getAppTasks() List AppTask 获取与调用应用程序关联的任务列表
getDeviceConfigurationInfo() ConfigurationInfo 获取设备配置属性。
getLargeMemoryClass() int 当应用程序在一个大堆中运行时,返回当前设备的每个应用程序的内存类。
getLauncherLargeIconDensity() int 获取Launcher的图标的首选密度。
getLauncherLargeIconSize() int 获取启动器的图标的首选密度。
getLockTaskModeState() int 返回当前任务锁定状态。
getMaxNumPictureInPictureActions() int 当用户与当前图片模式下的Activity进行交互时,将显示在图中UI中显示的最大动作数量。
getMemoryClass() int 返回当前设备的每个应用程序的内存类。
getMemoryInfo(ActivityManager.MemoryInfo outInfo) 返回关于系统内存状态的一般信息。
getMyMemoryState(ActivityManager.RunningAppProcessInfo outState) 为调用进程返回全局内存状态信息。
getProcessMemoryInfo(int[] pids) MemoryInfo[] 返回关于一个或多个进程的内存使用情况的信息。
getProcessesInErrorState() List ActivityManager.ProcessErrorStateInfo 返回当前处于错误状态的任何进程的列表。
getRunningAppProcesses() List ActivityManager.RunningAppProcessInfo 返回在设备上运行的应用程序进程列表。
getRunningServiceControlPanel(ComponentName service) PendingIntent 返回一个PendingIntent,您可以开始显示给定的运行服务的一个控制面板。
getRunningServices(int maxNum) List ActivityManager.RunningServiceInfo 返回当前运行的Services列表
isLowRamDevice() boolean 如果这是一个低ram设备,返回true。
isRunningInTestHarness() boolean 如果设备在一个测试工具中运行,则返回“true”。
isUserAMonkey() boolean 如果用户界面被Monkey messed,返回“true”。
killBackgroundProcesses(String packageName) 让系统立即终止与给定包关联的所有后台进程。
moveTaskToFront(int taskId, int flags, Bundle options) 请求与给定任务ID关联的任务被移动到堆栈的前面,因此用户现在可以看到它。
moveTaskToFront(int taskId, int flags) 同上
setVrThread(int tid) 为 latency-sensitive low-runtime VR线程启用更积极的调度。
setWatchHeapLimit(long pssSize) 请求系统开始监视调用进程,以超过pssSize

具体使用方式,还是用代码实现比较好理解:github位置:https://github.com/66668/ActivityManagerDemo
,代码将ActivityManager及其内部类的方法都打印出来,查看结果,其中比较重要的内部类是RunningServiceInfo,使用真机xplay6 android7.0测试,打印结果
发现,系统自行运行的Service有92个,大部分是厂商自己封装的service,见下表:

运行的Service 解释
com.android.bluetooth.hid.HidService
com.android.providers.media.MediaScannerNullService
com.vivo.daemonService.batterywarning.BatteryWarningService
org.codeaurora.ims.ImsService
com.qualcomm.location.LocationService
com.vivo.permissionmanager.service.FloatWindowManagerService
OneShotService
GalleryService
com.android.systemui.keyguard.KeyguardService
com.tencent.mm.plugin.sport.service.SportService
com.qualcomm.location.izat.IzatService
com.vivo.magazine.MagazineService
com.android.systemui.ImageWallpaper
com.android.providers.media.FileObserverService
com.vivo.permissionmanager.service.FileObserverService
com.bbk.launcher2.appstore.DownloadPackageService
com.qualcomm.qti.tetherservice.TetherService
WifiNetworkDetectService
com.android.bbklog.ServerControlLogService
com.tencent.mm.booter.NotifyReceiver$NotifyService
com.android.printspooler.model.PrintSpoolerService
com.vivo.appfilter.service.PreventAutoStartService
com.dsi.ant.server.AntService
com.qualcomm.location.izatserviceprovider.service.UnifiedLocationService
com.vivo.daemonService.vivolog.VivologAlarmService
com.vivo.daemonService.Nail.NailDaemonService
com.bbk.iqoo.logsystem.services.LogCollectService
com.vivo.daemonService.motion.DeviceListener
org.simalliance.openmobileapi.service.SmartcardService
com.vivo.messagecenter.display.DisplayService
com.vivo.pem.core.hide.io.PemService
com.vivo.daemonService.unifiedconfig.UnifiedConfigService
com.vivo.doubleinstance.WhitelistQureyService
com.vivo.push.core.android.service.MqttService
com.vivo.appbehavior.AppBehaviorEngineService
com.android.bluetooth.pbap.BluetoothPbapService
DuerTextToSpeechService
com.vivo.devicereg.ctrl.CtrlServer
com.vivo.nail.service.NailService
ClassifyService
com.vivo.daemonService.usb.UsbDeviceManagerService
com.vivo.daemonService.IqooSecure.SoftwareLockService
com.vivo.smartmultiwindow.services.ManagerStateService
ManagerStateService
com.android.bluetooth.a2dp.A2dpService
com.vivo.upslide.UpSlideService
com.qualcomm.qcrilmsgtunnel.QcrilMsgTunnelService
com.qti.service.colorservice.ColorServiceApp
com.vivo.download.DownloadService
com.baidu.location.f
com.vivo.smartmultiwindow.services.ScreenObserverService
com.vivo.daemonService.VoiceOneshot.OneShotService
com.android.systemui.SystemUIService
com.bbk.updater.usage.CalculateService
android.hardware.location.GeofenceHardwareService
com.vivo.core.AbeCoreService
com.iqoo.secure.wifidetect.WifiCheckService
com.vivo.push.sdk.service.PushService
com.iqoo.secure.service.SecureService
com.baidu.map.location.BaiduNetworkLocationService
com.qualcomm.location.LBSSystemMonitorService
com.vivo.smartmultiwindow.services.ThreeFinger
com.android.server.telecom.BluetoothPhoneService
com.vivo.findphone.CommandService
com.qualcomm.location.izatserviceprovider.service.NetworkLocationService
com.qti.dpmserviceapp.DpmServiceApp
com.qualcomm.qti.appnetaccess.AppNetAccessService
com.android.stk.StkAppService
com.vivo.daemonService.gms.GmsMonitor
com.vivo.doubletimezoneclock.clock.ClockWidgetService
com.vivo.safecenter.paysafe.PaySafeService
com.iqoo.secure.service.DataUsageService
com.baidu.duersdk.opensdk.service.DuerCoreSpeechRecognitionService
com.android.bluetooth.hfp.HeadsetService
com.vivo.performaengine.BigDataService
com.qti.qualcomm.datastatusnotification.DataStatusNotificationService cn.richinfo.dm.service.DMService
com.android.server.content.SyncJobService
com.vivo.daemonService.ProxCoverNotice.ProxCoverNoticeService
com.bbk.iqoo.logsystem.services.StartupIntentService
com.android.bbklog.BootLogParserService
com.vivo.daemonService.netStateStat.NetStateStatService
com.vivo.appfilter.service.VivoBringupManagerService
com.android.bluetooth.map.BluetoothMapService
com.android.mms.service.MmsService
com.android.defcontainer.DefaultContainerService
com.baidu.input_bbk.service.PinyinIME
android.ext.services.notification.Ranker
com.tencent.mobileqq.msf.service.MsfService
com.android.bluetooth.pan.PanService
com.android.server.telecom.smartdialer.BBKDialerInitService
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146004.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月16日 上午7:00
下一篇 2022年5月16日 上午7:00


相关推荐

  • GPS数据格式分析

    GPS数据格式分析GPS数据格式分析

    2022年6月23日
    28
  • Python中enumerate用法详解

    Python中enumerate用法详解enumerate 是 python 的内置函数 适用于 python2 x 和 python3 xenumerate 在字典上是枚举 列举的意思 enumerate 参数为可遍历 可迭代的对象 如列表 字符串 enumerate 多用于在 for 循环中得到计数 利用它可以同时获得索引和值 即需要 index 和 value 值的时候可以使用 enumerateenu 返回的是一个 enumerate 对象 s 1 2 3 4 5 e enumerate s print e 输出结

    2026年3月17日
    3
  • 【Anconda】关于安装Anaconda3各种各样的问题,吐血总结!!!(failed to create anacoda menu!!++)「建议收藏」

    【Anconda】关于安装Anaconda3各种各样的问题,吐血总结!!!(failed to create anacoda menu!!++)「建议收藏」昨天总结了装python和pycharm。本来想着马上接着总结Anaconda的,谁知道,这一安装,竟然花了我一天一夜的时间,(悲伤辣么大啊简直)。遇到了各种各样的问题,重装20几遍,每次问题都不同还。(掩面悲伤)直到刚才总算是可以了。面对问题的时候第一想法就是百度,结果尝试了所有百度的方法仍然无法解决问题。还是自己太笨了。总之,还是把自己遇到的问题总结一下把,以防不…

    2022年6月2日
    88
  • Android布局之表格布局[通俗易懂]

    Android布局之表格布局[通俗易懂]表格布局(Tablelayout) 简介:       Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。     当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。     当为View时,该View将独占一行。表格布局是以行和列的形式来对控件…

    2022年5月14日
    42
  • 软件性能测试包括哪些方面,简述软件系统性能指标主要包括哪些方面

    软件性能测试包括哪些方面,简述软件系统性能指标主要包括哪些方面软件系统性能指标可以衡量一个软件系统的运行效果 有关软件系统性能指标主要包括哪些方面呢 大致包括 时间效率 空间效率 事务操作性能 IO 性能 数据库性能 内存性能 初始化 退出时间 资源利用率等 这些都是软件系统性能指标的主要参考依据 下面一起来看看具体的软件系统性能指标有哪些细节吧 软件系统性能指标主要有哪些方面 1 事务处理时间 指软件中完成一项事物所需的运行时间 一般主要用来评价事务处理的效

    2026年3月26日
    2
  • EasyCVR通过Ehome协议接入部分设备显示离线排查报告

    EasyCVR通过Ehome协议接入部分设备显示离线排查报告对于需要将不同视频协议做融合的项目,我们一般都是建议大家选用EasyCVR视频平台,EasyCVR支持多种协议的视频接入,对于通用的第三方协议,我们支持了海康的Ehome和GB28181的国标协议。EasyCVR视频网关平台接入的部分Ehome设备显示离线,可以从下图中看到,除了通过HIKSDK接入的设备外,通过Ehome接入的设备全部离线:可见离线的部分设备都是Ehome协议接入,Ehome设备为主动注册类型,判断设备是否真实在线的方法一般为抓取对应对端口7660的包,或者是在海康sdk的回调

    2025年7月6日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号