public
interface
ComponentCallbacks2
implements
ComponentCallbacks
| android.content.ComponentCallbacks2 |
Fragment and FragmentManager APIs
instead; these are also
available on older platforms through the Android compatibility package.
<activity-alias> or subclass Activity directly.
MediaProjectionAppContent.
AppFunctionManager.executeAppFunction.
AutofillService is a service used to automatically fill the contents of the screen
on behalf of a given user - for more information about autofill, read
Autofill Framework.
TelecomManager.getDefaultDialerPackage()) or a third party app to allow or disallow
incoming calls before they are shown to a user.
android.app.NotificationManager.setAutomaticZenRuleState(String,Condition) to tell the
system about the state of your rule. In order to maintain a link from
Settings to your rule configuration screens, provide a configuration activity that handles
NotificationManager.ACTION_AUTOMATIC_ZEN_RULE on your
AutomaticZenRule via
android.app.AutomaticZenRule.setConfigurationActivity(ComponentName).
DialogFragment for consistent behavior across all devices
and access to Lifecycle.
RecyclerView or use
ExpandableListView directly
Fragment for consistent behavior across all devices
and access to Lifecycle.
Service class that can be
extended to emulate an NFC card inside an Android
service component.
Service class that can be
extended to emulate an NFC-F card inside an Android service component.
WorkManager
instead.
JobScheduler.
RecyclerView and
android.content.pm.PackageManager.queryIntentActivities(Intent,int)
ListFragment or
RecyclerView to implement your Activity instead.
ListFragment for consistent behavior across all devices
and access to Lifecycle.
androidx.media3.session.MediaSessionService
instead.
OffHostApduService is a convenience Service class that can be
extended to describe one or more NFC applications that are residing
off-host, for example on an embedded secure element or a UICC.
This is the base class for implementing print services.
QuickAccessWalletService provides a list of WalletCards shown in the Quick
Access Wallet.
ERROR(/android.os.Build.VANILLA_ICE_CREAM) and forward. If you are looking for a
framework that sends displayable data from one app to another, consider using
AppSearchManager.
Build.VERSION_CODES.DONUT.
VoiceInteractor, etc.
VoiceInteractionService.
WebView.onPause() and WebView.onResume()
Callbacks for app state transitions that can be used to improve background memory management.
This interface is available in all application components (Activity, Service, ContentProvider, and Application).
You should implement onTrimMemory(int) to release memory when your app goes to background
states. Doing so helps the system keep your app's process cached in memory for longer, such that
the next time that the user brings your app to the foreground, the app will perform a warm or hot start, resuming faster and
retaining state.
TRIM_MEMORY_UI_HIDDEN Bitmaps, or
resources related to video playback or animations.
TRIM_MEMORY_BACKGROUND Apps that continue to do work for the user when they're not visible can respond to the TRIM_MEMORY_UI_HIDDEN callback by changing their behavior to favor lower memory usage. For
example, a music player may keep full-sized album art for all tracks in the currently playing
playlist as Bitmaps cached in memory. When the app is backgrounded but music playback continues,
the app can change the caching behavior to cache fewer, or smaller, Bitmaps in memory.
The ordinal values for trim levels represent an escalating series of memory pressure events,
with incrementing values accordingly. More states may be added in the future. As such, it's
important not to check for specific values, but rather check if the level passed to onTrimMemory(int) is greater than or equal to the levels that your application handles. For example:
public void onTrimMemory(int level) {
if (level >= TRIM_MEMORY_BACKGROUND) {
// Release any resources that can be rebuilt
// quickly when the app returns to the foreground
releaseResources();
} else if (level >= TRIM_MEMORY_UI_HIDDEN) {
// Release UI-related resources
releaseUiResources();
}
}
Note: the runtime may invoke Garbage Collection (GC) in response to application state changes. There is no need to explicitly invoke GC from your app.
Constants | |
|---|---|
int |
TRIM_MEMORY_BACKGROUND
Level for |
int |
TRIM_MEMORY_COMPLETE
This constant was deprecated in API level 35. Apps are not notified of this level since API level 34 |
int |
TRIM_MEMORY_MODERATE
This constant was deprecated in API level 35. Apps are not notified of this level since API level 34 |
int |
TRIM_MEMORY_RUNNING_CRITICAL
This constant was deprecated in API level 35. Apps are not notified of this level since API level 34 |
int |
TRIM_MEMORY_RUNNING_LOW
This constant was deprecated in API level 35. Apps are not notified of this level since API level 34 |
int |
TRIM_MEMORY_RUNNING_MODERATE
This constant was deprecated in API level 35. Apps are not notified of this level since API level 34 |
int |
TRIM_MEMORY_UI_HIDDEN
Level for |
Public methods | |
|---|---|
abstract
void
|
onTrimMemory(int level)
Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. |
Inherited methods | |
|---|---|
public static final int TRIM_MEMORY_BACKGROUND
Level for onTrimMemory(int): the process has gone on to the
LRU list. This is a good opportunity to clean up resources that can
efficiently and quickly be re-built if the user returns to the app.
Constant Value: 40 (0x00000028)
public static final int TRIM_MEMORY_COMPLETE
This constant was deprecated
in API level 35.
Apps are not notified of this level since API level 34
Level for onTrimMemory(int): the process is nearing the end
of the background LRU list, and if more memory isn't found soon it will
be killed.
Constant Value: 80 (0x00000050)
public static final int TRIM_MEMORY_MODERATE
This constant was deprecated
in API level 35.
Apps are not notified of this level since API level 34
Level for onTrimMemory(int): the process is around the middle
of the background LRU list; freeing memory can help the system keep
other processes running later in the list for better overall performance.
Constant Value: 60 (0x0000003c)
public static final int TRIM_MEMORY_RUNNING_CRITICAL
This constant was deprecated
in API level 35.
Apps are not notified of this level since API level 34
Level for onTrimMemory(int): the process is not an expendable
background process, but the device is running extremely low on memory
and is about to not be able to keep any background processes running.
Your running process should free up as many non-critical resources as it
can to allow that memory to be used elsewhere. The next thing that
will happen after this is ComponentCallbacks.onLowMemory() called to report that
nothing at all can be kept in the background, a situation that can start
to notably impact the user.
Constant Value: 15 (0x0000000f)
public static final int TRIM_MEMORY_RUNNING_LOW
This constant was deprecated
in API level 35.
Apps are not notified of this level since API level 34
Level for onTrimMemory(int): the process is not an expendable
background process, but the device is running low on memory.
Your running process should free up unneeded resources to allow that
memory to be used elsewhere.
Constant Value: 10 (0x0000000a)
public static final int TRIM_MEMORY_RUNNING_MODERATE
This constant was deprecated
in API level 35.
Apps are not notified of this level since API level 34
Level for onTrimMemory(int): the process is not an expendable
background process, but the device is running moderately low on memory.
Your running process may want to release some unneeded resources for
use elsewhere.
Constant Value: 5 (0x00000005)
public static final int TRIM_MEMORY_UI_HIDDEN
Level for onTrimMemory(int): the process had been showing
a user interface, and is no longer doing so. Large allocations with
the UI should be released at this point to allow memory to be better
managed.
Constant Value: 20 (0x00000014)
public abstract void onTrimMemory (int level)
Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. You should never compare to exact values of the level, since new intermediate values may be added -- you will typically want to compare if the value is greater or equal to a level you are interested in.
To retrieve the processes current trim level at any point, you can
use ActivityManager.getMyMemoryState(RunningAppProcessInfo).
levelint: The context of the trim, giving a hint of the amount of
trimming the application may like to perform.
TRIM_MEMORY_COMPLETETRIM_MEMORY_MODERATETRIM_MEMORY_BACKGROUNDTRIM_MEMORY_UI_HIDDENTRIM_MEMORY_RUNNING_CRITICALTRIM_MEMORY_RUNNING_LOWTRIM_MEMORY_RUNNING_MODERATEContent 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 2026-03-26 UTC.