Just read a little service-related books, do notes, and hope to help people in need.
First of all, the development of service and activity is similar, also requires two steps:
First, define a subclass that inherits the service
Second, configure the service in the Androidmanifest.xml file
The service life cycle method is as follows:
1. Abstract IBinder onbind (Intent Intent): This method is a method that the service subclass must implement. The method returns an IBinder object that the application can use to communicate with the service component
2, void OnCreate (): The method is immediately called back when the service is created for the first time
3. void OnDestroy (): Callback the method before the service is closed
4, int onstartcommand (Intent Intent, int flags, int startid): The client calls the StartService (Intent) method to call back the method when the service is started
5. Boolean onunbind (Intent Intent): The method will be recalled when the client used to bind the service disconnects
Two ways to start service in Android:
1, through the context of the StartService () method: The service initiated by this method, the visitor is not associated with the service, even if the visitor exits, the service continues to run.
2, through the context of the Bindservice () method: The service started with the method, the visitor is bound to the service, and when the visitor exits, the service exits and stops running.