Android applications have their default running modes. To understand it, you must understand the activity lifecycle and visibility cycle.
Once the program is executed, it first enters oncreate and onstart. The rewrite method can be selected through eclipse. The method is relatively simple. Just right-click the blank area of the class that integrates the activity and choose source> override/implement methods.
In the displayed dialog box, select the onstart method to be rewritten.
Eclipse generates the followingCode
Package idroidgame. activitytest; import Android. App. Activity; import Android. OS. Bundle;Public ClassActivitytest extends activity {/** Called when the activity is first created .*/@ OverridePublic VoidOncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. Main );}@ OverrideProtected VoidOnstart (){// Todo auto-generated method stubSuper. onstart ();}}
Add other methods to be overwritten, and so on.
onresume () and onpause: When the Program loses focus or is disabled, the onpause () of the activity will be promoted (); when the program is awakened again, it will trigger onresume (). Therefore, in the process of processing a program, when temporarily leaving an activity or service, it should be processed in onpause. Take a download program as an example. If you want to pause the download, You can process it in onpause. If you want to continue, you can proceed in onresume.