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