To ensure Activity Responds to status changes, Android Provides a series of event processors. When Activity In its Full , Visible And Active These processors are triggered during lifetime migration. Figure 3-8 Just Activity Status, which outlines these lifetime.
Figure3-8
The following frameworkCodeAActivityMethod processor for available state change events. There are some prompts in each method, describing the recommended actions in each state change event.
Package com. paad. myapplication;
Import Android. App. activity;
Import Android. OS. Bundle;
Public class myactivity extends activity {
// InFullLife cycle.
@ Override
Public void oncreate (bundle icicle ){
Super. oncreate (icicle );
// InitializationActivity.
}
// InOncreateCalled after completion to restoreUIStatus.
@ Override
Public void onrestoreinstancestate (bundle savedinstancestate ){
Super. onrestoreinstancestate (savedinstancestate );
// Restore from savedinstancestateUIStatus.
// The bundle object is also passed in the oncreate method.
}
// InVisibleCalled before service life.
@ Override
Public void onrestart (){
Super. onrestart ();
// Load the changes. ThisActivityAlready visible.
}
// InVisibleLife cycle.
@ Override
Public void onstart (){
Super. onstart ();
// Required by the applicationUIChange. Now,ActivityVisible.
}
// InActiveLife cycle.
@ Override
Public void onresume (){
Super. onresume ();
// Resume pausedUIUpdate, thread, or whenInactiveThe process to be paused.
}
// InActiveEnd of Life call to saveUIStatus change.
@ Override
Public void onsaveinstancestate (bundle savedinstancestate ){
// SaveUIThe status changes to savedinstancestate.
// When the process is killed or restarted, the bundle is passed into the oncreate method.
Super. onsaveinstancestate (savedinstancestate );
}
// InActiveEnd of Life call.
@ Override
Public void onpause (){
// AbortUIUpdate, thread, orCPUA strong process (whenActivityNo longerActiveFront-endActivityDoes not need to be updated)
Super. onpause ();
}
// InVisibleEnd of Life call.
@ Override
Public void onstop (){
// AbortUIUpdate, thread, orActivityInvisible Process
// Save the data and status changes.
// When this is called, the process may be killed.
Super. onstop ();
}
// InFullEnd of Life call.
@ Override
Public void ondestroy (){
// Clear any resources, including closing threads and closing database connections.
Super. ondestroy ();
}
}
As shown in the code snippet above, when youOverrideWhen processing these functions, you must always call the functions of the parent class.