Summarize and improve, with June mutual encouragement!
1. What is the service?
The Service is not visible to the interface, is a non-interface activity, and long-term running in the background of a component.
Because of the limitations of the ANR response time to activity and broadcastreceiver (the activity responds to events for no more than 5 seconds, Broadcastreceiver executes no more than 10 seconds), making it unsuitable for more time-consuming operations like networks, The execution of time-consuming operations such as databases and complex computations requires a component to bear. Service as one of the four components of Android, one of its functions is the execution of time-consuming operations.
2. How to start service
There are two main types, bound and unbound
(1) Start with call Context.startservice () and End with call Context.stopservice ()
(2) Set to call the Context.bindservice () method to call Context.unbindservice () to close
Note:
Call the StartService () method to start the service, and the system will callback the service class's OnCreate () and the OnStart () method. This starts the Service running in the background until the Context.stopservice () or Selfstop () method is called. In addition, if a Service has been started, the other code attempts to call the StartService () method, is not executed onCreate (), but will be re-executed once OnStart () .
Another way to Bindservice () is to tie the service to the client class that invokes the service, and if the call to this client class is destroyed, the service will be destroyed .
3. Service life cycle
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Service Summary of four components