Monitor status changes

Source: Internet
Author: User

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.

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.