AndroidMemoryPressureObserver

MemoryPressureObserver driven by Android's ComponentCallbacks2.onTrimMemory / onLowMemory.

Registers on the application context at construction; close unregisters it (idempotent).

Parameters

context

any context; its application context is used.

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard

The most recently reported level, or MemoryPressureLevel.NORMAL if none has been reported.

Functions

Link copied to clipboard
open override fun addListener(listener: MemoryPressureListener): AutoCloseable

Registers listener. Closing the returned handle unregisters it; closing it more than once is a no-op.

Link copied to clipboard
open override fun close()

Unregisters from the application context. Idempotent.

Link copied to clipboard
fun emit(newLevel: MemoryPressureLevel)

Records newLevel as currentLevel and notifies every registered listener in registration order.