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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 手机JAVA编程技术[通俗易懂]

    JAVA手机编程技术林天峰(温州职业技术学院计算机系浙江

    2022年4月11日
    56
  • 如何通俗的理解函数的极限_不理解函数极限的定义![通俗易懂]

    如何通俗的理解函数的极限_不理解函数极限的定义![通俗易懂]极限定义里,为什么用“存在”“任意”“不等式”的数学语言来定义极限?怎样将普通语…楼主的问题显然是有备而来,是经过严格逻辑分析后有感而发的问题。确确实实,我们的高数教师,在教极限时,其实他们的大多数,也只是跟着和尚就念经,跟着道士就画符。解释来解释去就是那么死板板的几句话,连他们自己也没有makesense,教师如此,教科书如此,学生也只能以葫芦画瓢,难以彻底理解。下面尝试一下,看看能不…

    2022年5月22日
    35
  • HttpSession的生命周期和何时销毁

    HttpSession的生命周期和何时销毁HttpSession生命周期:1.什么时候创建HttpSession1).对于JSP:是否浏览器访问服务端的任何一个JSP或Servlet,服务器都会立即创建一个HttpSession对象呢?不一定。①.若当前的JSP或(Servlet)是客户端访问的当前WEB应用的第一个资源,且JSP的page指定的session属性为false,则服务器就不会为JSP创建一个HttpSess…

    2022年7月12日
    15
  • 字符串类型的时间和时间类型的相互转换

    字符串类型的时间和时间类型的相互转换publicstaticDategetDate(StringsDate)throwsException{Datedate=newDate(); SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");  //要转换的格式SimpleDateFormatsdf2=newSimpleDateFormat("yyy…

    2022年5月15日
    31
  • 大疆网上测评题库_一份完整的大疆2018校招笔试题和面经送给大家~

    大疆网上测评题库_一份完整的大疆2018校招笔试题和面经送给大家~听说周日大疆就要笔试了,今年的秋招来的有点让人猝不及防啊,牛客的各种讨论群里都弥漫着一种恐惧的氛围,我是谁,我在哪,我该怎么办(惊恐脸)。。。。。哈哈哈没关系,作为一个刚刚踏上工作岗位的老学长,去年秋招在牛客网收获颇丰,是时候来回馈一波牛客网,回报一下牛妹了;)话不多说,干货奉上2018秋招大疆机器学习、算法笔试题1、两个小车,走一步能量消耗1,方向为1向右,-1为向左,首先输入路途长度,然后输…

    2022年6月29日
    95
  • HBase实战:记一次Safepoint导致长时间STW的踩坑之旅

    HBase实战:记一次Safepoint导致长时间STW的踩坑之旅本文记录了HBase中Safepoint导致长时间STW此问题的解决思路及办法。上篇文章回顾:HBaseReplication详解过程记录现象:小米有一个比较大的公共离线HBase集群,用户很多,每天有大量的MapReduce或Spark离线分析任务在进行访问,同时有很多其他在线集群Replication过来的数据写入,集群因为读写压力较大,且离线分析任务对延迟不…

    2025年5月25日
    0

发表回复

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

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