Real portal application of Android Program

Source: Internet
Author: User

 

I have been in touch with Android for some time. I always thought that the entrance of the android program is the activity specified in the configuration file. I recently read an open-source project and found that the Android Application class is implemented, the real portal of the android program is the oncreate method of the application class. However, most developers do not need to override this class. Its Inheritance relationships are as follows: Java. Lang. Object
Using Android. content. Context
Using Android. content. contextwrapper
Using Android. App. Application

The android. App. Application class contains four public methods.
Void onconfigurationchanged (configuration newconfig)
Void oncreate () // here is the real entry point.
Void onlowmemory ()
Void onterminate ()

The following is the test code:
Two steps are required to use the application: 1. Rewrite the application class; 2. Configure the application in the configuration file.
The sample code is as follows:
MyApp class:

Package app. app;
Import Android. App. Application;
Import Android. content. res. configuration;
Public class MyApp extends application {
@ Override
Public void onconfigurationchanged (configuration newconfig ){
Super. onconfigurationchanged (newconfig );
}
@ Override
Public void oncreate (){
Super. oncreate ();
System. Out. println ("MyApp is called ");
}
@ Override
Public void onlowmemory (){
Super. onlowmemory ();
}
@ Override
Public void onterminate (){
Super. onterminate ();
}
}


Configuration file:
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name" Android: Name = "app. App. MyApp">
......
</Application>

Activity Class:
Public void oncreate (bundle savedinstancestate ){

Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
System. Out. println ("mainactivity is called ");

}

Result: MyApp is called mainactivity is called.

NOTE 1: In Android, application is just a loose characterization concept, and there is not much substantive representation [which is significantly different from the MIDlet of j2_m2.] Application class, representing the context state of the application, is a concept of extreme weakening. Application is just a concept of spatial category, and application is the context description of components such as activity and service. Application is not the core concept of Android, but activity is the core concept of Android.
Note 2: The myapplication class is used to place global variables and methods in some contexts.

Original article: Real portal application of Android Program
Http://www.pocketcn.com/forum-viewthread-tid-1565-fromuid-1477.html

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.