Service Concept and use:
A service is an application component that can perform long-running operations in the background and does not provide a US Er interface. Typically the service is used to perform sometime-consuming OperationOrBackground Executiondoes not provide user interaction interface, such as: Download, play music.
service life cycle:The life cycle of Android service is not as complex as activity, it only inheritsonCreate (), OnStart (), OnDestroy ( )Three methods, when we first start the service, have called OnCreate (), OnStart () These two methods, whenStop Serviceis executed when theOnDestroy ()method, it is important to note that if the service has been started, when weStart service againis not executed when theonCreate ()method, but executes the onstart () method directly.1 by StartService
Service Experience onCreate-OnStart
Direct OnDestroy when StopService.
if the caller (testserviceholder) exits without calling StopService's
, the service will always run in the background.
next testserviceholder up again can stopservice.
2 by Bindservice
the service will only run OnCreate, and this time Testserviceholder and Testservice are bound together
Testserviceholder exits, Srevice will call onunbind->ondestroyed.
The so-called binding together is a common survival. The service cannot run itself and needs to start the service by calling the Context.startservice () or Context.bindservice () method. Both of these methods can start the service, but they are used in different situations. The service is enabled with the StartService () method, the caller is not connected to the service, and the service is still running even if the caller exits. Using the Bindservice () method to enable the service, the caller and the service are bound together, and once the caller exits, the service terminates, and there is a "no need to live at the same time Must Die" feature.
? Service "Android"