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


相关推荐

  • 什么是模型,什么是模式

    模型(model)与模式(Pattern),英文显然是两个词,但是,在实际使用过程中,却是比较混乱。虽然,我还不清楚厘清这两个词的关系,对基层的数学工作者有怎样的价值,但是至少对理解什么是数学是有益处的,能够帮助我们不止是了解数学的结论,而且了解数学的思考方法。  一、模型与数学模型     (一)模型的定义:     数学辞海第5卷第109页有关于模型的定义:模型

    2022年4月6日
    38
  • 前端,什么是跨域,及跨域常见的解决方案(简讲)「建议收藏」

    前端,什么是跨域,及跨域常见的解决方案(简讲)「建议收藏」认识跨域解决跨域

    2022年5月18日
    37
  • 轻松搞懂【TF-IDF、word2vec、svm、cnn、textcnn、bilstm、cnn+bilstm、bilstm+attention实现】英文长文本分类[通俗易懂]

    轻松搞懂【TF-IDF、word2vec、svm、cnn、textcnn、bilstm、cnn+bilstm、bilstm+attention实现】英文长文本分类[通俗易懂]项目来源:https://www.kaggle.com/c/word2vec-nlp-tutorial/之前我写过几篇博客:就这?word2vec+BiLSTM、TextCNN、CNN+BiLSTM、BiLSTM+Attention实现中英文情感分类代码详解就这?word2vec+SVM(支持向量机)实现中英文情感分类代码详解这两篇博客主要是基于中文进行情感分类的,那么本篇博客,我会以这个kaggle项目来介绍如何实现英文长文本情感分类。1实验数据本次数据集来源于kaggle项目“Bago

    2022年6月28日
    31
  • matlab超前滞后校正装置设计_matlab劳斯判据

    matlab超前滞后校正装置设计_matlab劳斯判据且1引言不确定性与时滞是工业过程中普通存在的现象,这使得系统的分析与综合变得更加复杂和困难,同时也是导致系统不稳定和性能恶化的主要因素.因此,对不确定时滞系统的鲁棒控制问题进行研究,具有重要的理论意义和实际应用价值.近年来,不确定时滞系统的稳定性研究得到了广泛的关注匡5}.中立时滞系统作为一类非常重要的控制系统,其稳定性研究己有不少有价值的结论{3一11}.中立时滞系统的稳定条件可分为两大类:时滞…

    2022年9月30日
    5
  • JSP/Servlet工作原理[通俗易懂]

    JSP/Servlet工作原理[通俗易懂]JSP/Servlet工作原理ServletServlet没有main方法,不能够独立运行,它的运行需要容器的支持,Tomcat是最常用的JSP/Servlet容器。Servlet运行在Servlet容器中,并由容器管理从创建到销毁的整个过程Servlet的生命周期加载和实例化Servlet容器装载和实例化一个Servlet。创建出该Servlet类的一个实例。初始化在Servlet

    2022年10月4日
    4
  • python批量修改文件夹名称_python文件扩展名主要有

    python批量修改文件夹名称_python文件扩展名主要有1、引言需要把.dat格式转化成.txt格式2、实现##python批量更换后缀名importos#列出当前目录下所有的文件files=os.listdir(‘.’)#print(‘files’,files)forfilenameinfiles:portion=os.path.splitext(filename)#如果后缀是.datifp

    2026年2月19日
    7

发表回复

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

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