Android Development-Application class

Source: Internet
Author: User

This digest is from Google's Android website translation, if there is wrong place, please the Great God Guidance

Website: http://developer.android.com/reference/android/app/Application.html


Application,activity,service,content provider are all system components of the Android framework, and when the Android program starts, a Application object is created to store some information about the system.


Launching an Android application is tantamount to starting a process where a process has only one Application object


Well, before Activity,service,broadcast,content provider, it was application.


So application belongs to a singleton pattern.


Sometimes we need to do some initialization on the custom application.



<span style= "FONT-SIZE:14PX;" >public class MyApplication extends application{    private static final String URL = "Http://api.demo.com/login"; C1/>private String value;        @Override public    void OnCreate ()    {        super.oncreate ();        SetValue (VALUE); Initialize global variable    } public        void SetValue (String value)    {        this.value = value;    }        Public String GetValue ()    {        return value;    }} </span>

We can set and get this URL in activity,service,broadcast,content provider.


Of course there are nine other methods of this class that we can rewrite.

onCreate () called when application is created

onlowmemory () The memory consumed by the application process is eliminated when the entire system is low on memory

registeractivitylifecyclecallbacks ( application.activitylifecyclecallbacks callback)

            Register activity lifecycle callback

registercomponentcallbacks ( componentcallbacks callback)

            Register component callbacks

registeronprovideassistdatalistener ( application.onprovideassistdatalistener callback)

            Registration data persistence is called, that is, the commonly said cache

unregisteractivitylifecyclecallbacks ( application.activitylifecyclecallbacks callback)

            Unregister the activity lifecycle callback

unregistercomponentcallbacks ( componentcallbacks callback)

            Unregister component callbacks

unregisteronprovideassistdatalistener ( application.onprovideassistdatalistener callback)

Unregister data Persistence


Android Development-Application class

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.