欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android.content.ComponentCallbacks

程序员文章站 2022-05-18 11:35:27
/* * copyright (c) 2006 the android open source project * * licensed under the apache licen...
/*
 * copyright (c) 2006 the android open source project
 *
 * licensed under the apache license, version 2.0 (the "license");
 * you may not use this file except in compliance with the license.
 * you may obtain a copy of the license at
 *
 *https://www.apache.org/licenses/license-2.0
 *
 * unless required by applicable law or agreed to in writing, software
 * distributed under the license is distributed on an "as is" basis,
 * without warranties or conditions of any kind, either express or implied.
 * see the license for the specific language governing permissions and
 * limitations under the license.
 */

package android.content;

import android.content.res.configuration;

/**
 * the set of callback apis that are common to all application components
 * ({@link android.app.activity}, {@link android.app.service},
 * {@link contentprovider}, and {@link android.app.application}).
 *
 * 

note: you should also implement the {@link * componentcallbacks2} interface, which provides the {@link * componentcallbacks2#ontrimmemory} callback to help your app manage its memory usage more * effectively.

*/ public interface componentcallbacks { /** * called by the system when the device configuration changes while your * component is running. note that, unlike activities, other components * are never restarted when a configuration changes: they must always deal * with the results of the change, such as by re-retrieving resources. * *

at the time that this function has been called, your resources * object will have been updated to return resource values matching the * new configuration. * *

for more information, read handling runtime changes. * * @param newconfig the new device configuration. */ void onconfigurationchanged(configuration newconfig); /** * this is called when the overall system is running low on memory, and * actively running processes should trim their memory usage. while * the exact point at which this will be called is not defined, generally * it will happen when all background process have been killed. * that is, before reaching the point of killing processes hosting * service and foreground ui that we would like to avoid killing. * *

you should implement this method to release * any caches or other unnecessary resources you may be holding on to. * the system will perform a garbage collection for you after returning from this method. *

preferably, you should implement {@link componentcallbacks2#ontrimmemory} from * {@link componentcallbacks2} to incrementally unload your resources based on various * levels of memory demands. that api is available for api level 14 and higher, so you should * only use this {@link #onlowmemory} method as a fallback for older versions, which can be * treated the same as {@link componentcallbacks2#ontrimmemory} with the {@link * componentcallbacks2#trim_memory_complete} level.

*/ void onlowmemory(); }