# OnTrimMemoryProvider

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/OnTrimMemoryProvider.kt+class:androidx.core.content.OnTrimMemoryProvider) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

*** ** * ** ***

<br />

```
interface OnTrimMemoryProvider
```

<br />

Known direct subclasses [ComponentActivity](https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity` | Base class for activities that enables composition of higher level components. |

Known indirect subclasses [AppCompatActivity](https://developer.android.com/reference/kotlin/androidx/appcompat/app/AppCompatActivity), [BaseCarAppActivity](https://developer.android.com/reference/kotlin/androidx/car/app/activity/BaseCarAppActivity), [CarAppActivity](https://developer.android.com/reference/kotlin/androidx/car/app/activity/CarAppActivity), [FragmentActivity](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity), [LauncherActivity](https://developer.android.com/reference/kotlin/androidx/car/app/activity/LauncherActivity), [PreviewActivity](https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/PreviewActivity)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appcompat/app/AppCompatActivity` | Base class for activities that wish to use some of the newer platform features on older Android devices. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/activity/BaseCarAppActivity` | Core logic for CarAppLibrary Activity interaction with a host. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/activity/CarAppActivity` | The class representing a car app activity in the main display. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` | Base class for activities that want to use the support-based `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/activity/LauncherActivity` | This class handles providing the right launcher activity when running native applications and Car App Library applications. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/PreviewActivity` | Activity used to run `@Composable` previews from Android Studio. |

*** ** * ** ***

Interface for components that can dispatch calls from `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)`.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/content/OnTrimMemoryProvider#addOnTrimMemoryListener(androidx.core.util.Consumer)(listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>)` Add a new listener that will get a callback associated with `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)` with the `int` representing the level of trimming. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/content/OnTrimMemoryProvider#removeOnTrimMemoryListener(androidx.core.util.Consumer)(listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>)` Remove a previously added listener. |

## Public functions

### addOnTrimMemoryListener

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
fun addOnTrimMemoryListener(listener: Consumer<Int>): Unit
```

Add a new listener that will get a callback associated with `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)` with the `int` representing the level of trimming.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | The listener that should be called whenever `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)` was called. |

### removeOnTrimMemoryListener

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
fun removeOnTrimMemoryListener(listener: Consumer<Int>): Unit
```

Remove a previously added listener. It will not receive any future callbacks.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | The listener previously added with .addOnTrimMemoryListener that should be removed. |