(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. flask livereload用法

    #coding=utf-8 from flask import Flask from flask_script import Manager app = Flask(__name__) manager ...

  2. 51开发环境的搭建--KeilC51的安装及工程的创建

    学习单片机的开发,单靠书本的知识是远远不够的,必须实际操作编程才能领会书中的知识点,起到融会贯通的效果.51单片机作为入门级的单片机--上手容易.网上资源丰富.单片机稳定性及资源比较丰富.通过串口即可 ...

  3. MVC项目的简单总结

    不能说是庆幸吧,正赶上公司要开发一个小小的MVC项目,于是这样任务就只有我自己承担,在这个项目中我才彻底感觉到自己之前有关MVC知识的无知,以为接触了皮毛就感觉能做项目,只要有心动脑思考就能完成一个完 ...

  4. iOS - Action Extension

    上一篇<iOS开发 之 Share Extension>介绍了分享扩展的开发与使用,本篇主要还是讲述在系统分享菜单中最底下一栏的功能扩展:Action Extension,该扩展跟Shar ...

  5. vmp3.0.9全保护拆分解析

    https://mp.weixin.qq.com/s/WO6w_L-cYwH5KB2rilZdag 以下为了避免插件干扰,故采用x64dbg原版进行分析. 首先我通过检测到调试器的弹窗进行栈回溯,定位 ...

  6. iptables 介绍

    规则链 规则链的作用:对数据包进行过滤或处理 链的作用:容纳各种防火墙规则 链的分类依据:处理数据包的不同时机 默认包括5种规则链 INPUT:处理入站数据包 OUTPUT:处理出站数据包 FORWA ...

  7. 【Spring系列】Spring IoC

    前言 IoC其实有两种方式,一种是DI,而另一种是DL,即Dependency Lookup(依赖查找),前者是当前软件实体被动接受其依赖的其他组件被IOc容器注入,而后者是当前软件实体主动去某个服务 ...

  8. JS笔记 - JQ事件委托( 适用于给动态生成的脚本元素添加事件)

    最近一段时间打了一个大仗,现在总算消停点,才有时间来做个总结吧算是: 移动端遇到一个项目,是一个列表的侧滑栏,在我这里用jq写的交互事件.自测各方面都挺好的,美滋滋的给了研发.研发也美滋滋的开始开发. ...

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

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

  10. smarty直接在模板中格式化时间的方法

    smarty提供了一个获取时间戳的方法: <%$smarty.now%> 使用该方法获取到当时的时间戳之后,使用格式化修饰符data-format进行修饰: <%$smarty.no ...