Application Introduction (ii)--Rewriting the lifecycle events of an application

Source: Internet
Author: User

The application class changes event handlers for application creation and finalization, low-availability memory, and configuration, and you can implement your own application behavior for several of these scenarios by overriding these methods:

1. OnCreate: This method is called when the application is created. You can override this method to instantiate application configurations, or you can create and instantiate any application state variables or shared resources.

2, Onlowmemory: This method is generally only in the background process has been terminated, but the foreground application is still missing memory when called. You can override this handler to empty the cache or release unnecessary resources.

3. Ontrimmemory: As an application-specific alternative to onlowmemory, it is introduced in Android 4.0 (API level13). Called when the runtime determines whether the current application should attempt to reduce its memory overhead (usually when it enters the background). It contains a level parameter that provides the context for the request.

4, onconfigurationchanged and activity, when the configuration changes, the Application object will not be terminated and restarted, if the application uses a value that depends on a specific configuration, then override this method to reload the value, or processing configuration changes at the application level.

Note: You must call the parent class's event handlers when overriding these methods.

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.