Android onCreate onStart onresume onPause onStop OnDestroy

Source: Internet
Author: User

An activity in Android typically requires the implementation of six functions:

OnCreate (), OnStart (), Onresume (), OnPause (), OnStop (), OnDestroy ().

OnCreate function: Register the variables you want to use, such as service,receiver, whether your activity is responsive in the foreground or in the background, and then call the function initialized above to initialize the layout information.

OnStart function: Register some variables. These variables must be available at the front of the Android activity class to be able to respond.

Onresume function: Call some functions that refresh the UI and refresh the state of the UI controls whenever the activity is called here.

OnPause function: The general is to do some variable settings, because this time the activity will be cut to the background processing, may be some variables will be released or the state to do some corresponding adjustment.

OnStop function: Unregister the variable registered in the OnStart function.

Ondestory function: Unregister the variable registered in the OnCreate function.

In the Android-hello,

public class Ubilrnactivity extends Activity {
/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
}

First, life has a oncreate function, and the incoming parameter of this function is savedinstancestate. Type is Bundle,bundle is a data parameter, typically used for data transfer between activity. The parameters of OnCreate () are all bundle classes.

Super.oncreate represents a call to the parent class, OnCreate.

Setcontentview (R.layout.main) is the resource that loads the system by loading main.xml.

Android onCreate onStart onresume onPause onStop OnDestroy

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.