1. What startup methods does the Service have? What is the difference? What is Service: Service? The name is similar to the "Service" that we normally understand. It runs in the background and can interact with each other. It is similar to the Activity level, but it cannot be run by itself. It needs to be called through an Activity or other Context object, Context. startService () and Context. bindService (). The two methods for starting a Service are different: If you do some time-consuming tasks in onCreate or onStart of the Service, you 'd better start a thread in the Service to complete the process, because the Service runs in the main thread, it will affect UI operations or block other tasks in the main thread. When Service is required: for example, when the user starts other activities during multimedia playback, the program needs to continue playing in the background, for example, detecting file changes on the SD card, or record the changes in your geographic information location in the background. In short, the service is always hidden in the back. How to Use Service: Service to call Context. startService (): the Service will go through onCreate-> onStart (if the Service is not running, android first calls onCreate () and then calls onStart (); if the Service is already running, only onStart () is called, so the onStart method of a Service may be called multiple times). When stopService is called, onDestroy is called directly. If the caller directly exits without calling stopService, the Service is always running in the background. After the Service caller starts up again, the Service can be closed through stopService. Note that Context is called multiple times. startservice () is not nested (even if the corresponding onStart () method is called), no matter how many times the same service is started, Once Context is called. stopService () or stopSelf. Note: Intent objects passed to startService () are passed to the onStart () method. The call sequence is onCreate --> onStart (which can be called multiple times) --> onDestroy. Context. bindService (): the Service will go through onCreate ()-> onBind (), onBind will return to the client an IBind interface instance, IBind allows the client to call back the Service method, for example, you can obtain the Service running status or other operations. At this time, the caller (such as Activity) will be bound with the Service, and the Context will exit, and Srevice will call onUnbind-> onDestroyed to exit accordingly, the so-called binding together will survive. Note: Intent objects passed to bindService () will be passed to onBind (), Intent objects passed to unbindService () will be passed to onUnbind () method. The call sequence is onCreate --> onBind (only once, cannot be bound multiple times) --> onUnbind --> onDestory. Note: during each Service enabling and disabling process, only onStart can be called multiple times (through multiple startService calls), other onCreate, onBind, onUnbind, onDestory can only be called once in a lifecycle. Another point is that I have never encountered a situation where the interaction between startService and bindService is required (I don't think there will be such a requirement), so I don't have to consider the issue of interaction, so it is not too late to consider the treatment. AdcastReceiver can only start the Service through startService, because the life cycle of the broadcast itself is very short, bind does not mean the life cycle of the Service: www.2cto. comService has fewer lifecycle methods than Activity. Only onCreate, onStart, and onDestroy can be used to start a Service in two ways. Their impact on the Service lifecycle is different. 1. The startService will experience onCreate-> onStart. When stopService is used, onDestroy is used directly. If the caller (TestServiceHolder) Exits without calling stopService, the Service will continue to run in the background. The next time TestServiceHolder gets up again, it can be stopService. 2. Through bindService Service, only onCreate is run. At this time, TestServiceHolder and TestService are bound together with TestServiceHolder and quit. Srevice will call onUnbind-> onDestroyed. In fact, there is another third type: Cross-process communication: AIDL. This can also start the service.