What did the Android app silently do when it started the activity and called the OnCreate () method?

Source: Internet
Author: User

What did the Android app silently do when it started the activity and called the OnCreate () method?
 There are two sentences in the <intent-filter> element in the Androidmanifest.xml file:


<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>


When a well-written app is posted to the phone, when you double-click the app's icon, the system wraps the click Time as a intent, which contains two parameters, two parameters as described above are passed to the app, and the intent filter that matches the intent is found in the app's feature manifest file.If the match succeeds, find the activity element that matches the intent filter, and then according to
The "name" attribute of the <activity> element to find its corresponding activity class. Then, AThe ndroid operating system creates an instance object of the activity class that executes the OnCreate method to the class after the object is created .,
This oncreate method is implemented by overriding the OnCreate method of the parent class activity. The OnCreate method is used to initialize the activity instance object. The following is the code for the OnCreate method in the Helloworld.java class:


public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}


The function of Super.oncreate (savedinstancestate) is to invoke the OnCreate method of its parent activity to realize the drawing work of the interface.
It is important to remember to call this method when implementing the OnCreate method of your defined activity subclass to ensure that the interface is drawn.


Super.oncreate is mainly loaded with some components.
The first thing is Super.oncreate (savedinstancestate), in fact, this statement is placed in the subclass of the OnCreate method in any position can be, the problem is only
Super.oncreate (Savedinstancestate) has to be executed, so it's best to put it on the first line and look more specific.


The OnCreate method has been rewritten in targetactivity, and some basic bases have been manipulated in the OnCreate method in activity. If the subclass does not have a call to the Super.oncraete method, it causes the OnCreate method in the subclass to function incorrectly, resulting in an error.


In the activity life cycle, as long as you leave the visible phase, or lose focus, the activity is likely to be terminated by the process! , was killed,, at this time, it is necessary to have a mechanism to preserve the state of the moment, this is the role of savedinstancestate.
When an activity is in pause, it can be called before the kill.
Onsaveinstancestate () to save the state information of the current activity (when the paused state is being killed). The bundle that holds the state information is passed to the two method, Onrestoreinstancestate () and OnCreate ().




The role of Setcontentview (R.layout.main) is to load an interface. The parameter passed in the method is "R.layout.main", meaning that the static constant of the static inner class layout in the R.java class is the value of main,
The change is a pointer to the identifier of the Main.xml file under the layout subdirectory of the Res directory. This represents the display of the main.xml defined by the image.




Reference documents
Http://www.android100.org/html/201406/10/23627.html

Http://wenku.baidu.com/link?url= Uxm2tc7wljk5aihtt9eqxk3xflkbyzbxdijg1fcsw5blzjermau5-gvhowd8msswkowud8ohhj6iklaufulfq18od-usabnhiaky2imcsy_

What did the Android app silently do when it started the activity and called the OnCreate () method?

Related Article

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.