public interface ComponentCallbacks2 extends ComponentCallbacks
ComponentCallbacks
interface with a new callback for
finer-grained memory management.Modifier and Type | Field and Description |
---|---|
static int |
TRIM_MEMORY_BACKGROUND
Level for
onTrimMemory(int) : the process has gone on to the
LRU list. |
static int |
TRIM_MEMORY_COMPLETE
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. |
static int |
TRIM_MEMORY_MODERATE
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. |
static int |
TRIM_MEMORY_RUNNING_CRITICAL
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. |
static int |
TRIM_MEMORY_RUNNING_LOW
Level for
onTrimMemory(int) : the process is not an expendable
background process, but the device is running low on memory. |
static int |
TRIM_MEMORY_RUNNING_MODERATE
Level for
onTrimMemory(int) : the process is not an expendable
background process, but the device is running moderately low on memory. |
static int |
TRIM_MEMORY_UI_HIDDEN
Level for
onTrimMemory(int) : the process had been showing
a user interface, and is no longer doing so. |
Modifier and Type | Method and Description |
---|---|
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.
|
onConfigurationChanged, onLowMemory
static final int TRIM_MEMORY_COMPLETE
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.static final int TRIM_MEMORY_MODERATE
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.static final int TRIM_MEMORY_BACKGROUND
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.static final int TRIM_MEMORY_UI_HIDDEN
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.static final int TRIM_MEMORY_RUNNING_CRITICAL
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.static final int TRIM_MEMORY_RUNNING_LOW
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.static final int TRIM_MEMORY_RUNNING_MODERATE
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.void onTrimMemory(int level)
To retrieve the processes current trim level at any point, you can
use ActivityManager.getMyMemoryState(RunningAppProcessInfo)
.
level
- The context of the trim, giving a hint of the amount of
trimming the application may like to perform. May be
TRIM_MEMORY_COMPLETE
, TRIM_MEMORY_MODERATE
,
TRIM_MEMORY_BACKGROUND
, TRIM_MEMORY_UI_HIDDEN
,
TRIM_MEMORY_RUNNING_CRITICAL
, TRIM_MEMORY_RUNNING_LOW
,
or TRIM_MEMORY_RUNNING_MODERATE
.