(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. Mock

    转移到  这里 像测试对象提供一套和测试资源完全相同 的接口和方法,不关心过程,只关心结果(比如模拟拿到服务器的code)

  2. 状态保持以及AJAX的初步学习

    嘿嘿,今天学习的有点迷茫哦,主要学习把验证码使用在登录页面时间的一些逻辑,学习这个时间并没有那么的迷惑哦,可是自己写程序时间倒是有点反应迟钝,不过还好总是在最后搞清楚啦,另外就是一步一步的学习是接近项 ...

  3. Ubuntu下Eclipse的安装方法

    1. 下载jre,eclipse,cdt 其中jre是java运行环境,eclipse需要先装jre,才可能运行,cdt是在eclipse中运行c\c++程序的插件. 1.1 下载jre 网址是:ja ...

  4. springboot---->springboot中的格式化(一)

    这里面我们简单的学习一下springboot中关于数据格式化的使用.我以为你不是个好人,没想到你连个坏人都不是. springboot中的格式化 我们的测试环境是springboot,一个将字符串格式 ...

  5. 转载->C#中的委托的使用和讲解

    C# 中的委托 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容 ...

  6. 转载>>ASCII、UTF8、Uncicode编码下的中英文字符大小

    原地址:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part2.aspx ASCII.UTF8.Uncicode编码 ...

  7. java(2) 面向对象

    1.类的封装 *在定义一个类时,将类中的属性私有化,即使用prviate关键字来修饰,私有属性只能在它所在的类中被访问.为了能让外界访问私有属性,需要提供一些使用public修饰的公有方法,其中包括用 ...

  8. LeetCode 9 Palindrome Number(回文数字判断)

    Long Time No See !   题目链接https://leetcode.com/problems/palindrome-number/?tab=Description   首先确定该数字的 ...

  9. [原]RHEL7/Centos 7将网卡名称改为eth0

    ======问题===== rhel的网卡为enoxxxxxxxxx =====原因====== 从CentOS/RHEL7起,可预见的命名规则变成了默认.这一规则,接口名称被自动基于固件,拓扑结构和 ...

  10. SOS does not support the current target architecture解决方法

    客户提交一个dump文件,WinDbg加载时出现大量WARNING,加载对应版本的SOS后执行相应命令提示"SOS does not support the current target a ...