Java 在onStartCommand中为服务返回的内容
我一直在浏览文档,有时Java 在onStartCommand中为服务返回的内容,java,android,Java,Android,我一直在浏览文档,有时onStartCommand()返回START\u NOT\u STICKY,有时返回以下内容: @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub return super.onStartCommand(intent, flags, startId); } 我现在不明白为什么有些服务返
onStartCommand()
返回START\u NOT\u STICKY
,有时返回以下内容:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
return super.onStartCommand(intent, flags, startId);
}
我现在不明白为什么有些服务返回
super.onStartCommand(intent、flags、startId)代码>这取决于你想要什么。报告说:
为了向后兼容,默认实现调用onStart(Intent,int)并返回START\u或STICKY
启动粘性兼容性
因此返回super.onStartCommand()
相当于返回START\u STICKY
。如果不需要默认行为,可以返回另一个常量。最常用的是
- Service.START\u粘性
- Service.START\u不粘且
- 服务。启动\u重新交付\u意图
如果android系统因任何原因终止,Service.START\u STICKY将重新启动。
Service.START\u NOT\u STICKY将一直运行,直到有挂起的工作为止。
Service.START\u REDELIVER\u的意图与Service.START\u类似,但最初的意图会重新传递给onStartCommand方法。谢谢您的回答。。我有一个问题。。如果我的服务中没有覆盖onStartCommand()
,那么默认情况下会返回什么值?系统将如何对待我的服务重新启动/停止??我认为它将返回START\u粘性
Service.START_STICKY
>> the system restarts the service with everything refresh not using the previous intent.
Service.START_NOT_STICKY
>> the system does not restarts the service.
Service.START_REDELIVER_INTENT
>>the system restarts the service with using the previous intent.`enter code here