Udostępnij za pośrednictwem


IComponentCallbacks2 Interface

Definition

Extended ComponentCallbacks interface with a new callback for finer-grained memory management.

[Android.Runtime.Register("android/content/ComponentCallbacks2", "", "Android.Content.IComponentCallbacks2Invoker")]
public interface IComponentCallbacks2 : Android.Content.IComponentCallbacks, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("android/content/ComponentCallbacks2", "", "Android.Content.IComponentCallbacks2Invoker")>]
type IComponentCallbacks2 = interface
    interface IComponentCallbacks
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

Extended ComponentCallbacks interface with a new callback for finer-grained memory management. This interface is available in all application components (android.app.Activity, android.app.Service, ContentProvider, and android.app.Application).

You should implement #onTrimMemory to incrementally release memory based on current system constraints. Using this callback to release your resources helps provide a more responsive system overall, but also directly benefits the user experience for your app by allowing the system to keep your process alive longer. That is, if you <em>don't</em> trim your resources based on memory levels defined by this callback, the system is more likely to kill your process while it is cached in the least-recently used (LRU) list, thus requiring your app to restart and restore all state when the user returns to it.

The values provided by #onTrimMemory do not represent a single linear progression of memory limits, but provide you different types of clues about memory availability:

<ul> <li>When your app is running: <ol> <li>#TRIM_MEMORY_RUNNING_MODERATE<br>The device is beginning to run low on memory. Your app is running and not killable. <li>#TRIM_MEMORY_RUNNING_LOW<br>The device is running much lower on memory. Your app is running and not killable, but please release unused resources to improve system performance (which directly impacts your app's performance). <li>#TRIM_MEMORY_RUNNING_CRITICAL<br>The device is running extremely low on memory. Your app is not yet considered a killable process, but the system will begin killing background processes if apps do not release resources, so you should release non-critical resources now to prevent performance degradation. </ol> </li> <li>When your app's visibility changes: <ol> <li>#TRIM_MEMORY_UI_HIDDEN<br>Your app's UI is no longer visible, so this is a good time to release large resources that are used only by your UI. </ol> </li> <li>When your app's process resides in the background LRU list: <ol> <li>#TRIM_MEMORY_BACKGROUND<br>The system is running low on memory and your process is near the beginning of the LRU list. Although your app process is not at a high risk of being killed, the system may already be killing processes in the LRU list, so you should release resources that are easy to recover so your process will remain in the list and resume quickly when the user returns to your app. <li>#TRIM_MEMORY_MODERATE<br>The system is running low on memory and your process is near the middle of the LRU list. If the system becomes further constrained for memory, there's a chance your process will be killed. <li>#TRIM_MEMORY_COMPLETE<br>The system is running low on memory and your process is one of the first to be killed if the system does not recover memory now. You should release absolutely everything that's not critical to resuming your app state.

To support API levels lower than 14, you can use the #onLowMemory method as a fallback that's roughly equivalent to the ComponentCallbacks2#TRIM_MEMORY_COMPLETE level. </li> </ol> <p class="note"><strong>Note:</strong> When the system begins killing processes in the LRU list, although it primarily works bottom-up, it does give some consideration to which processes are consuming more memory and will thus provide more gains in memory if killed. So the less memory you consume while in the LRU list overall, the better your chances are to remain in the list and be able to quickly resume.

</li> </ul>

More information about the different stages of a process lifecycle (such as what it means to be placed in the background LRU list) is provided in the Processes and Threads document.

Java documentation for android.content.ComponentCallbacks2.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
OnConfigurationChanged(Configuration)

Called by the system when the device configuration changes while your component is running.

(Inherited from IComponentCallbacks)
OnLowMemory()

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.

(Inherited from IComponentCallbacks)
OnTrimMemory(TrimMemory)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to