Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在onStartCommand中为服务返回的内容_Java_Android - Fatal编程技术网

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