Skip to content

Instantly share code, notes, and snippets.

@brucetoo
Created July 13, 2015 13:09
Show Gist options
  • Save brucetoo/4fef373d3d0f13debfc1 to your computer and use it in GitHub Desktop.
Save brucetoo/4fef373d3d0f13debfc1 to your computer and use it in GitHub Desktop.
service onStartCommand的返回值
onStartComand 可以有四个返回值:START_STICKY、START_NO_STICKY、START_REDELIVER_INTENT、START_STICKY_COMPATIBILITY。
它们的含义分别是:
1):START_STICKY:如果service进程被kill掉,保留service的状态为开始状态,但不保留递送的intent对象。随后系统会尝试重新创建service,由于服务状态为开始状态,所以创建服务后一定会调用onStartCommand(Intent,int,int)方法。如果在此期间没有任何启动命令被传递到service,那么参数Intent将为null。
2):START_NOT_STICKY:“非粘性的”。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统不会自动重启该服务
3):START_REDELIVER_INTENT:重传Intent。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统会自动重启该服务,并将Intent的值传入。
4):START_STICKY_COMPATIBILITY:START_STICKY的兼容版本,但不保证服务被kill后一定能重启
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment