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() 从起动到后台再到前台: ...
随机推荐
- 集群瓶颈为什么是磁盘io
阅读本文思考: 1.对磁盘IO了解多少 2.为什么是磁盘IO是瓶颈,有没有自己的答案 想了解磁盘io可以查看此帖:集群瓶颈:磁盘IO必读 (磁盘IO:磁盘输出输出) 集群的瓶颈提出多种看法,其中网络和 ...
- Mock
转移到 这里 像测试对象提供一套和测试资源完全相同 的接口和方法,不关心过程,只关心结果(比如模拟拿到服务器的code)
- 【cs229-Lecture5】生成学习算法:1)高斯判别分析(GDA);2)朴素贝叶斯(NB)
参考: cs229讲义 机器学习(一):生成学习算法Generative Learning algorithms:http://www.cnblogs.com/zjgtan/archive/2013/ ...
- MFC 常见问题
一 常见变量获得 CDC * cDc=GetDC(); HDC m_Screenhdc = this->GetDC()->m_hDC; // 整个窗口客户区的坐标 this->Ge ...
- slave库写redo、binlog不实时丢数据的场景
1.slave涉及相关文件 slave读取master的binlog日志后,需要落地3个文件:relay log.relay log info.master info: relay log: 即读取过 ...
- vue组件定义方式
一.全局组件 <div id="box"> {{msg}} <my-aaa></my-aaa> </div> var Home = ...
- 删除个别主机的Know_hosts文件信息
方法一: rm -rf ~/.ssh/known_hosts 缺点:把其他正确的公钥信息也删除,下次链接要全部重新经过认证 方法二: vi ~/.ssh/known_hosts 删除对应ip的相关rs ...
- Debian的自动化安装(DEBIAN_FRONTEND)
Debian 安装程序的参数 安装系统确认一些附加的引导参数 debconf/priority 这些参数设置将设置显示的信息为为最低的级别. 缺省安装使用 debconf/priority=high ...
- Coding 代码管理快速入门(转)
当项目创建好了之后,我们该如何上传代码到 coding 上呢? Coding 网站使用“ Git 仓库”(类似 github )来管理代码. 其操作原理在于:利用 git 服务,将本地的项目目录下的文 ...
- iOS - 开源框架、项目和学习资料汇总(UI篇)
上下拉刷新控件 1. MJRefresh --仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明.(推荐)2. SV ...