Services

地址:https://developer.android.com/guide/components/services.html#Basics

为了确保你的应用安全,通常使用显示的方法来启动service,不要声明intent filters 给service。

如果让service 支持intent filters而不用组件名称,必须在intent中设置包名setPackage(),

onStartCommand()必须返回一下的参量:

1、START_NOT_STICKY

如果系统杀死了service,不会重新创建service,除非重新发送intent,

2、START_STICKY

如果系统杀死了service,会重新启动service,调用onStartCommand(),但是不会发送上一次的intent,系统调用onStartCommand()时intent为null,

3、START_REDELIVER_INTENT

如果系统杀死了service,会重新创建service,并调用onStartCommand(),并且会传上一次的intent。






你可能感兴趣的:(Services)