During Android development, the Onstartcommand (Intent,int,int) method of the service object is called every time StartService (Intent) is called. Then do some processing in the Onstartcommand method. Then we notice that this function has an int return value, and this article simply tells the effect of the int return value. From the official Android documentation, we know that Onstartcommand has 4 return values: start _sticky: If the service process is killed, the status of the service is kept in a start state, However, the delivery of the intent object is not preserved. The system then tries to recreate the service, and since the service status is started, the Onstartcommand (Intent,int,int) method must be called after the services are created. If no startup commands are passed to the service during this time, then the parameter intent will be null. START_not_sticky: "Non-sticky". When this return value is used, the service is not automatically restarted if the service is killed by an exception after Onstartcommand is executed. START_redeliver_intent: Retransmission INTENT. With this return value, if the service is killed by an exception after Onstartcommand is executed, the service is automatically restarted and the value of intent is passed in. start_sticky_compatibility: The compatible version ofstart_sticky, but does not guarantee that the service will be restarted after kill.
Service class Onstartcommand in Android