Functions provided by application activity and their usage

Source: Internet
Author: User

The Android.app.Application class provides a number of methods similar to OnCreate (), which are recalled by the Android framework in different scenarios. At the same time, the application class provides a number of monitoring functions to monitor the life cycle of components in this application. As shown in the following table:

Method name return value
Annotations
Onconfigurationchanged (Configuration newconfig) void If the device configuration (including language, orientation, network, etc.) changes when the component is running, the system calls this method to notify the application
OnCreate () void This method is called when the application is starting up, and before any other application objects are created. Because the time spent on this feature directly affects the speed at which the first activity service or receiver is started in a process, it executes as quickly as possible (for example, with a slow initialization state). If you override this method, you need to make sure that you call super.oncreated ()
It is important to note that in a real application, if some components in your application specify a process attribute (the processes) and this process does not exist, then the application OnCreate () callback is called, in other words, this method may be called multiple times
Onlowmemory () void The system calls this method to notify the application when the entire system is running low on memory and wants the application to reduce memory usage. But when the exact point of the call to this method is undefined, it usually occurs near the time that all background processes have been terminated.
The application can perform this method to free any buffers or unnecessary resources that it owns. The system runs a garbage collection operation after it returns from this method.
Onterminate () void This method is used in a simulation process environment and is not invoked on the production Android device, and can be removed by simply terminating the process on the production Android device. Do not execute any user code (including this callback) when you remove work
Ontrimmemory () void Called when the memory is reclaimed. For example, when it goes into the background and there is not enough memory to keep many background processes running.
Monitoring Callback Interface
Registercomponentcallbacks
Unregistercomponentcallbacks
void

void
Register an Componentcallbacks interface in the application. The application is notified through the various methods of this interface before the activity life cycle has changed. Using this interface, we can do the necessary processing before the activity life cycle changes
It is important to note that the Componentcallbacks object must be removed at the appropriate time in the future, using Unregistercomponentcallbacks (componentcallbacks). It was previously registered with Registercomponentcallbacks (componentcallbacks).

Functions provided by application activity and their usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.