(1)START_NOT_STICKY

  If the system kills the service after onStartCommand() returns, do not recreate the service, unless there are pending intents to deliver.

This is the safest option to avoid running your service when not necessary and when your application can simply restart any unfinished jobs.

(2)START_STICKY

  If the system kills the service after onStartCommand() returns, recreate the service and callonStartCommand(), but do not redeliver the last intent.

Instead, the system calls onStartCommand() with a null intent, unless there were pending intents to start the service, in which case, those intents

are delivered. This is suitable for media players (or similar services) that are not executing commands, but running indefinitely and waiting for a job.

(3)START_REDELIVER_INTENT

  If the system kills the service after onStartCommand() returns, recreate the service and call onStartCommand()with the last intent that was delivered

to the service. Any pending intents are delivered in turn. This is suitable for services that are actively performing a job that should be immediately

resumed, such as downloading a file.

public static final int START_NOT_STICKY

  This mode makes sense for things that want to do some work as a result of being started, but can be stopped when under memory pressure and will

explicit start themselves again later to do more work. An example of such a service would be one that polls for data from a server: it could schedule an alarm

to poll every N minutes by having the alarm start its service. When its onStartCommand(Intent, int, int) is called from the alarm, it schedules a new alarm for

N minutes later, and spawns a thread to do its networking. If its process is killed while doing that check, the service will not be restarted until the alarm goes off.

 

public static final int START_STICKY

  If this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)),then leave it in the started state but don't retain this

delivered intent. Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after

creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must

take care to check for this.

  This mode makes sense for things that will be explicitly started and stopped to run for arbitrary periods of time, such as a service performing background music playback.

 

Service 的 onStartCommand(Intent, int, int) 返回值的更多相关文章

  1. Intent获取Activity返回值

    /* Intent获取Activity返回值* 三步:* 子Activity关闭后的返回值处理函数,requestCode是子Activity返回的请求码,与页面顶端的两个请求码相匹配,resultC ...

  2. println()函数输出int类型返回值错误的问题

    out.println(); 在用这个语句输出其他类返回大的int类型的数据的时候,注意输出错误. 例如: out.println(class1.方法()):  导致错误: our.println(c ...

  3. C语言中,int型函数返回值可以为bool型。

    参考:https://bbs.csdn.net/topics/360116265. 问题: 如一个函数如下: int aa( int a, int b ) //举个例子,不要纠结功能. {  if(a ...

  4. 【移动开发】Service类onStartCommand()返回值和参数

    Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...

  5. Android中Service类onStartCommand的返回值问题

    Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...

  6. C语言中fgetc函数返回值为什么是int?

    学习C语言的,文件操作,大都会用到它. 它的函数原型: 这个函数的返回值,是返回读取的一个字节.如果读到文件末尾返回EOF.EOF其实就是一个宏#define EOF (-1)表示-1.既然返回的是一 ...

  7. Android中Service类onStartCommand

    Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...

  8. Android - 和其他APP交互 - 获得activity的返回值

    启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...

  9. Activity的跳转及返回值 的四种方法

    Activity生命周期 从创建到销毁的生命周期: onCreate()→onStart()→onResume()→onPouse()→onStop()→onDestroy() 从起动到后台再到前台: ...

随机推荐

  1. [Cubieboard] 在 Cubieboard 上安装 Node.js 和 npm

    你有两个选择可以实现在Cubieboard上安装NodeJS,下载别人已经编译完成适用于Cubieboard的NodeJS二进制包,或者自己下载源码自行在Cubieboard上进行编译. 使用编译完成 ...

  2. 【LeetCode OJ】Swap Nodes in Pairs

    题目:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2 ...

  3. 【小程序+ thinkphp5】 获取微信运动数据

    配置.请参看上篇文章.这里直接上代码 PHP 代码: //获取微信运动数据: public function test(){ $code = input("code"); $sig ...

  4. Python基础---->python的使用(二)

    学习一下python,这里对python的基础知识做一个整理.似等了一百年忽而明白,即使再见面,成熟地表演,不如不见. python的一些应用 一.类似于java中的MessageFormat用法 w ...

  5. PCL—低层次视觉—关键点检测(Harris)

    除去NARF这种和特征检测联系比较紧密的方法外,一般来说特征检测都会对曲率变化比较剧烈的点更敏感.Harris算法是图像检测识别算法中非常重要的一个算法,其对物体姿态变化鲁棒性好,对旋转不敏感,可以很 ...

  6. javascript prototype学习

    function foo(a, b, c) { return a*b*c; } alert(foo.length); alert(typeof foo.constructor); alert(type ...

  7. centos7和Ubuntu上的关机需要手动关闭电源的问题

    author:heandsen chen date: 2018-11-11  20:36:38. # halt  执行后会出现这个问题 解决办法: # init 0 # shutdown -h now ...

  8. MySQL知识小结

    MySQL的知识面试中还是经常被问到的,简单的使用似乎无法达到面试官的要求,很多问题会关于Mysql存储引擎,所以这里还是需要系统学习一下Mysql的一些知识,面试过程中游刃有余. MySQL体系结构 ...

  9. 几个解决k染色问题的指数级做法

    几个解决k染色问题的指数级做法 ——以及CF908H题解 给你一张n个点的普通无向图,让你给每个点染上k种颜色中的一种,要求对于每条边,两个端点的颜色不能相同,问你是否存在一种可行方案,或是让你输出一 ...

  10. Spring Cloud Eureka 高可用注册中心

    参考:<<spring cloud 微服务实战>> 在微服务架构这样的分布式环境中,各个组件需要进行高可用部署. Eureka Server 高可用实际上就是将自己作为服务向其 ...