Stay organized with collections
Save and categorize content based on your preferences.
android.os.health
The android.os.health package contains a set of classes to provide data
to track the system resources of applications.
Applications running in the background are responsible for a significant amount
of battery usage on a typical android device. There are several things that
applications can do in order to reduce their impact. For example, by using
JobScheduler
, an application does not need
to independently monitor whether the network is available, whether the device is
plugged in, etc. In addition to being simpler to use, the application's
services are only started when the required conditions have been met. But even
when using the appropriate helper APIs, applications still can reduce their
footprint. This package provides more insight into what is going on behind the
scenes when an application is running.
Application data is tracked by which user id (uid) is using particular
resources. A snapshot of an application's measurements can be taken with the
SystemHealth.takeMyUidSnapshot()
method. The HealthStats
object returned contains the
statistics.
HealthStats
In order to be returned efficiently, the HealthStats
class uses a set of int keys to identify the data returned. The
UidHealthStats
, PidHealthStats
,
PackageHealthStats
, ProcessHealthStats
,
and ServiceHealthStats
classes provide those constants.
Each HealthStats
object will be associated with
exactly one of those classes. The object returned from
SystemHealth.takeMyUidSnapshot()
will be using the UidHealthStats
keys, as it contains all
of the data available for that uid.
Classes
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# android.os.health\n\nAdded in [API level 24](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nandroid.os.health\n=================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/os/health/package-summary \"View this page in Kotlin\") \\|Java\nThe android.os.health package contains a set of classes to provide data to track the system resources of applications.\n\n\nApplications running in the background are responsible for a significant amount\nof battery usage on a typical android device. There are several things that\napplications can do in order to reduce their impact. For example, by using\n[JobScheduler](/reference/android/app/job/JobScheduler), an application does not need\nto independently monitor whether the network is available, whether the device is\nplugged in, etc. In addition to being simpler to use, the application's\nservices are only started when the required conditions have been met. But even\nwhen using the appropriate helper APIs, applications still can reduce their\nfootprint. This package provides more insight into what is going on behind the\nscenes when an application is running.\n\n\nApplication data is tracked by which user id (uid) is using particular\nresources. A snapshot of an application's measurements can be taken with the\n[SystemHealth.takeMyUidSnapshot()](/reference/android/os/health/SystemHealthManager#takeMyUidSnapshot())\nmethod. The [HealthStats](/reference/android/os/health/HealthStats) object returned contains the\nstatistics.\n\n\n**HealthStats** \n\nIn order to be returned efficiently, the [HealthStats](/reference/android/os/health/HealthStats)\nclass uses a set of int keys to identify the data returned. The\n[UidHealthStats](/reference/android/os/health/UidHealthStats), [PidHealthStats](/reference/android/os/health/PidHealthStats),\n[PackageHealthStats](/reference/android/os/health/PackageHealthStats) , [ProcessHealthStats](/reference/android/os/health/ProcessHealthStats),\nand [ServiceHealthStats](/reference/android/os/health/ServiceHealthStats) classes provide those constants.\nEach [HealthStats](/reference/android/os/health/HealthStats) object will be associated with\nexactly one of those classes. The object returned from\n[SystemHealth.takeMyUidSnapshot()](/reference/android/os/health/SystemHealthManager#takeMyUidSnapshot())\nwill be using the [UidHealthStats](/reference/android/os/health/UidHealthStats) keys, as it contains all\nof the data available for that uid.\n\n\nClasses\n-------\n\n|-------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [HealthStats](/reference/android/os/health/HealthStats) | A HealthStats object contains system health data about an application. |\n| [PackageHealthStats](/reference/android/os/health/PackageHealthStats) | Keys for [HealthStats](/reference/android/os/health/HealthStats) returned from [HealthStats.getStats(int)](/reference/android/os/health/HealthStats#getStats(int)) with the [UidHealthStats.STATS_PACKAGES](/reference/android/os/health/UidHealthStats#STATS_PACKAGES) key. |\n| [PidHealthStats](/reference/android/os/health/PidHealthStats) | Keys for [HealthStats](/reference/android/os/health/HealthStats) returned from [HealthStats.getStats(int)](/reference/android/os/health/HealthStats#getStats(int)) with the [UidHealthStats.STATS_PIDS](/reference/android/os/health/UidHealthStats#STATS_PIDS) key. |\n| [ProcessHealthStats](/reference/android/os/health/ProcessHealthStats) | Keys for [HealthStats](/reference/android/os/health/HealthStats) returned from [HealthStats.getStats(int)](/reference/android/os/health/HealthStats#getStats(int)) with the [UidHealthStats.STATS_PROCESSES](/reference/android/os/health/UidHealthStats#STATS_PROCESSES) key. |\n| [ServiceHealthStats](/reference/android/os/health/ServiceHealthStats) | Keys for [HealthStats](/reference/android/os/health/HealthStats) returned from [HealthStats.getStats(int)](/reference/android/os/health/HealthStats#getStats(int)) with the [PackageHealthStats.STATS_SERVICES](/reference/android/os/health/PackageHealthStats#STATS_SERVICES) key. |\n| [SystemHealthManager](/reference/android/os/health/SystemHealthManager) | Provides access to data about how various system resources are used by applications. |\n| [TimerStat](/reference/android/os/health/TimerStat) | A TimerStat object stores a count and a time. |\n| [UidHealthStats](/reference/android/os/health/UidHealthStats) | Keys for [HealthStats](/reference/android/os/health/HealthStats) returned from [SystemHealthManager.takeUidSnapshot(int)](/reference/android/os/health/SystemHealthManager#takeUidSnapshot(int)), [SystemHealthManager.takeMyUidSnapshot()](/reference/android/os/health/SystemHealthManager#takeMyUidSnapshot()), and [SystemHealthManager.takeUidSnapshots(int[])](/reference/android/os/health/SystemHealthManager#takeUidSnapshots(int[])). |\n\n-\n\n Classes\n -------\n\n - [HealthStats](/reference/android/os/health/HealthStats)\n - [PackageHealthStats](/reference/android/os/health/PackageHealthStats)\n - [PidHealthStats](/reference/android/os/health/PidHealthStats)\n - [ProcessHealthStats](/reference/android/os/health/ProcessHealthStats)\n - [ServiceHealthStats](/reference/android/os/health/ServiceHealthStats)\n - [SystemHealthManager](/reference/android/os/health/SystemHealthManager)\n - [TimerStat](/reference/android/os/health/TimerStat)\n - [UidHealthStats](/reference/android/os/health/UidHealthStats)"]]