Note that the Onstartcommand () method must return an integer. This integer is a description of how the system should continue to run after the service is killed (
The default Intentservice implementation code in the previous section will handle this for you, and you will not be able to modify this process, of course.
The return value of Onstartcommand () must be one of the following constants:
-
Start_not_sticky
-
if the system kills the service after Onstartcommand () is returned, the service will not be rebuilt unless there is an unsent intent.
-
This is the safest option to avoid service runs when the service is no longer required and the application can simply restart those unfinished work.
-
Start_sticky
-
if the system kills the service after Onstartcommand () returns, it rebuilds the service and calls Onstartcommand ().
-
instead of feeding the previous intent again, the Onstartcommand () is called with a null intent. These remaining intent will continue to be sent, unless there are intent that have started the service
-
. This applies to media players (or similar services), which do not execute commands, but need to be running and ready to stand by.
-
Start_redeliver_intent
-
if the system kills the service after Onstartcommand () returns, it rebuilds the service and calls Onstartcommand () with the last intent that was sent.
-
Any intent that have not been sent will be fed in turn. This applies to active services that require immediate recovery, such as downloading files.
Android Four Components service (6) Sticky and non-sticky