Android development-Explanation of onCreate

Source: Internet
Author: User

 

When we create an Android project and open the java file under src, we will see the classes that have been written, but do you know what these are?

Digress: this evening, Mr. Chen gave me a lecture on how to get started with Android. I remember this question: the <intent-filter> element in the AndroidManifest. xml file contains the following two sentences:

<Intent-filter>

<Action android: name = "android. intent. action. MAIN"/>

<Category android: name = "android. intent. category. LAUNCHER"/>

</Intent-filter>

Do you know what the two sentences mean? Www.2cto.com

After a written application is published to a mobile phone, When you double-click the icon of the application in the "drawer", the system packs the click time into an Intent, which contains two parameters, after the two parameters mentioned above are passed to the application, find the intent filter that matches the intent in the application's function list file. If the match succeeds, find the Activity element of the matched intent filter, and find its corresponding activity Class Based on the "name" attribute of the <Activity> element. Then, the Android operating system creates an instance object for this Activity class. After the object is created, the onCreate method of this class is executed. This onCreate method is implemented by rewriting the onCreate method of the parent Activity class. The onCreate method is used to initialize the Activity instance object. The code for the onCreate method in the helloWorld. java class is as follows:

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. main );

}

The role of super. onCreate (savedInstanceState) is to call the onCreate method of its parent Activity to draw pictures on the interface. When implementing the onCreate method of the Activity subclass defined by yourself, remember to call this method to ensure that the interface can be drawn.

SetContentView (R. layout. main) is used to load an interface. The input parameter in this method is "R. layout. main ", which means R. in the java class, the value of the static constant main of the static internal class layout is changed to the main under the layout subdirectory under the res directory. the identifier of the xml file. Therefore, the screen defined in main. xml is displayed.

From yangbo_hbzjk's column

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.