AndroidMemoryPressure

Implementation of MemoryPressure for Android.

In the Android system, ComponentCallbacks2 is used to monitor memory pressure states. It notifies the memory pressure state based on the level parameter of ComponentCallbacks2.onTrimMemory.

| Android Trim Level             | MemoryPressureLevel   |
|:-------------------------------|:----------------------|
| TRIM_MEMORY_UI_HIDDEN          | Low                   |
| TRIM_MEMORY_BACKGROUND         | Low                   |
| TRIM_MEMORY_MODERATE           | Low                   |
| TRIM_MEMORY_RUNNING_MODERATE   | Low                   |
| TRIM_MEMORY_RUNNING_LOW        | Low                   |
| TRIM_MEMORY_COMPLETE           | Critical              |
| TRIM_MEMORY_RUNNING_CRITICAL   | Critical              |

Constructors

Link copied to clipboard
constructor(context: Context)

Types

Link copied to clipboard

Implementation of ComponentCallbacks2 for observing memory pressure.

Functions

Link copied to clipboard
open override fun addObserver(observer: MemoryPressure.Observer)

Adds an observer to receive events.

Link copied to clipboard
open fun asFlow(): Flow<MemoryPressureLevel>

Provides a Flow to receive events of memory pressure.

Link copied to clipboard
open override fun removeObserver(observer: MemoryPressure.Observer)

Removes an observer that receives events.