Android Four components

Source: Internet
Author: User

The four components of Android are:

--activity

--service

--broadcastreceiver

--content Provider

An Activity

Activity provides an interface for users to interact with the application

1> inherits Android's activity class

2> overriding OnCreate methods

3> Setting the display layout

4> in the Androidmanifest file, register activity

Life cycle of activity

OnCreate (); create

OnStart (); run

Onresume (): Recover, get focus

OnPause (); Pause, lose focus

OnStop (); stop

OnDestroy (); destroy

Onrestart (); restart


Code Validation:

public class Mainactivity extends Activity {


Private String TAG = "mainactivity";
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
}


/**
* <pre>
* OnCreate: (describes the role of the method.)
* </pre>
* @author: Administrator 2014-12-31
*/
protected void OnCreate () {
TODO auto-generated Method Stub
Super.onstart ();
LOG.I (TAG, "mainactivity==>oncreate");
}


/**
* TODO simply describes the implementation functionality of the overridden method (optional).
* @author Administrator 2014-12-31
* @see Android.app.activity#onstart ()
*/
@Override
protected void OnStart () {
TODO auto-generated Method Stub
Super.onstart ();
LOG.I (TAG, "Mainactivity==>onstart");
}
/**
* TODO simply describes the implementation functionality of the overridden method (optional).
* @author Administrator 2014-12-31
* @see Android.app.activity#onresume ()
*/
@Override
protected void Onresume () {
TODO auto-generated Method Stub
Super.onresume ();
LOG.I (TAG, "Mainactivity==>onresume");
}
/**
* TODO simply describes the implementation functionality of the overridden method (optional).
* @author Administrator 2014-12-31
* @see Android.app.activity#onpause ()
*/
@Override
protected void OnPause () {
TODO auto-generated Method Stub
Super.onpause ();
LOG.I (TAG, "mainactivity==>onpause");
}
/**
* TODO simply describes the implementation functionality of the overridden method (optional).
* @author Administrator 2014-12-31
* @see Android.app.activity#onstop ()
*/
@Override
protected void OnStop () {
TODO auto-generated Method Stub
Super.onstop ();
LOG.I (TAG, "mainactivity==>onstop");
}
/**
* TODO simply describes the implementation functionality of the overridden method (optional).
* @author Administrator 2014-12-31
* @see Android.app.activity#ondestroy ()
*/
@Override
protected void OnDestroy () {
TODO auto-generated Method Stub
Super.ondestroy ();
LOG.I (TAG, "Mainactivity==>ondestroy");
}





Android Four components

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.