android basis of a <Service hybrid approach to open service>

Requirements: If you want to invoke a service inside the interface, there do not want the service to be destroyed when the activity ends, then start the service on the use of mixed mode.

 

Start the service: bindService and startService alphabetical order

Intent  intent=new Intent(MainActivity.this,MyService.class);
bindService(intent,serviceConnect,BIND_AUTO_CREATE);
startService(intent);

 

Destruction Services: 

Call service tied to a separate solution method, callback services will not be destroyed only onUnbind 
unbindService (serviceConnect);
A separate call to stop the service method, service will not be destroyed 
stopService (intent);

 NOTE: You must be simultaneous calls stopService unbindService methods and services to be stopped, that is to say as long as there is a way to survive, the service will continue to run.

            Since Acitvity exit automatically calls unbindService destruction service, so the activity which calls stopService method, after exiting the service activity will be automatically destroyed.

 

Guess you like

Origin www.cnblogs.com/jtzp007/p/11482094.html