Service 的 onStartCommand(Intent, int, int) 返回值
(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) 返回值的更多相关文章
- Intent获取Activity返回值
/* Intent获取Activity返回值* 三步:* 子Activity关闭后的返回值处理函数,requestCode是子Activity返回的请求码,与页面顶端的两个请求码相匹配,resultC ...
- println()函数输出int类型返回值错误的问题
out.println(); 在用这个语句输出其他类返回大的int类型的数据的时候,注意输出错误. 例如: out.println(class1.方法()): 导致错误: our.println(c ...
- C语言中,int型函数返回值可以为bool型。
参考:https://bbs.csdn.net/topics/360116265. 问题: 如一个函数如下: int aa( int a, int b ) //举个例子,不要纠结功能. { if(a ...
- 【移动开发】Service类onStartCommand()返回值和参数
Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...
- Android中Service类onStartCommand的返回值问题
Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...
- C语言中fgetc函数返回值为什么是int?
学习C语言的,文件操作,大都会用到它. 它的函数原型: 这个函数的返回值,是返回读取的一个字节.如果读到文件末尾返回EOF.EOF其实就是一个宏#define EOF (-1)表示-1.既然返回的是一 ...
- Android中Service类onStartCommand
Android开发的过程中,每次调用startService(Intent)的时候,都会调用该Service对象的onStartCommand(Intent,int,int)方法,然后在onStart ...
- Android - 和其他APP交互 - 获得activity的返回值
启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...
- Activity的跳转及返回值 的四种方法
Activity生命周期 从创建到销毁的生命周期: onCreate()→onStart()→onResume()→onPouse()→onStop()→onDestroy() 从起动到后台再到前台: ...
随机推荐
- Splash jsfunc() 方法
jsfunc()方法可以直接调用 JavaScript 定义的方法,但是所调用的方法需要用双中括号包围,这相当于实现了 JavaScript 方法到 Lua 脚本的转换 function main(s ...
- Nginx 72万连接性能测试(一)
转自:http://my.oschina.net/chenzhuo/blog/150200?p=2#comments 根据系统内存64G估算单台tengine做反向代理最高支持72万连接.为了验证达到 ...
- (原)android修改文件所属的用户组
首先得安装了busybox: 命令如下: busybox fileName 其中的0表示root,改成1000则表示system,改成2000则表示shell.
- (原)强类型dataset(类型化dataset)中动态修改查询条件(不确定参数查询)
原创博客,转载请注明:http://www.cnblogs.com/albert1017/p/3361932.html 查询时有多个参数,参数个数由客户输入决定,不能确定有多少个参数,按一般的方法每种 ...
- Web负载均衡与分布式架构
参考帖子: Web负载均衡的几种实现方式 大型网站架构系列:负载均衡详解(上) DNS 原理入门 解决nginx负载均衡的session共享问题 什么是消息队列 Java应用架构的演化之路 Java ...
- 百度地图API接口
js <script type="text/javascript"> // 百度地图API功能 var map = new BMap.Map("map&quo ...
- cnBlogs博客推荐
数据结构和算法若可以称为为编程的细胞结构,那设计模式就是编程的灵魂气脉. 一个从是编程的微观演绎,一个是编程的宏观设计.这个从技术和艺术的结合体,毫无疑问是在世界末日之前的很伟大的一项发明. 设计 ...
- spring基础---->spring自定义初始化(一)
这里我们简单的实现一下spring中的初始化bean,以大概了解他的流程.受委屈几乎是一个人成长最快的途径,吃下去的是委屈,消化掉后得到的是格局. spring的自定义初始化 测试的项目结构如下: 一 ...
- 【大数据系列】hadoop单机模式安装
一.添加用户和用户组 adduser hadoop 将hadoop用户添加进sudo用户组 sudo usermod -G sudo hadoop 或者 visudo 二.安装jdk 具体操作参考:c ...
- 安装cnpm
使用淘宝镜像的cnpm $ npm install -g cnpm --registry=https://registry.npm.taobao.org