AndroidIn development, when you need to createProgramService is required.
Services are different from activities (which can be understood as the difference between the background and the foreground ),
The Service startup process is as follows:
Context. startservice ()-> oncreate ()-> onstart ()-> Service Running
Here, oncreate () can initialize some services.
The process of stopping a service is as follows:
Context. stopservice () |-> ondestroy ()-> service stop
Example:
Public class myservice extends Service {@ overridepublic ibinder onbind (intent) {// todo auto-generated method stubreturn NULL;} @ override public void oncreate () {toast. maketext (this, "my service create", toast. length_short ). show () ;}@ overridepublic void ondestroy () {toast. maketext (this, "my service destroy", toast. length_short ). show () ;}@ overridepublic void onstart (intent, int startid) {toast. maketext (this, "my service started", toast. length_short ). show ();}}
Call:
@ Overridepublic void onclick (view v) {// todo auto-generated method stubswitch (v. GETID () {case R. id. startsevice: startservice (new intent (this, myservice. class); break; case R. id. stopservice: stopservice (new intent (this, myservice. class); break ;}}
When you call the startservice method, run the oncreate method and ondestroy method in myservice.
When the stopservice method is called, The ondestroy method is executed.