Service 中的 onStart 和 onStartCommand
在自定义的service中,写了onStart和onStartCommand,
public class HttpWebService extends Service {
@Override
public void onCreate() {
super.onCreate();
.... @Override
public void onStart(Intent intent, int startId) {
// this will trigger AbstractBackgroundService.onStart()
super.onStart(intent, startId);
Log.d(LOG_TAG, "onStart" + intent);
} @Override
public int onStartCommand(Intent intent, int flags, int startId) {
int retVal = super.onStartCommand(intent, flags, startId);
Log.d(LOG_TAG, "onStartCommand" + intent); return retVal;
} }
如果用 bindService 这种方式调用,onStart和onStartCommand都不会被调用到
this.bindService(new Intent(this, HttpWebService.class),
new ServiceConnection() { @Override
public void onServiceConnected(ComponentName name,
IBinder service) {
HttpWebService webService = ((HttpWebService.LocalBinder) service)
.getService();
webService.SetServerListener(webListener);
} @Override
public void onServiceDisconnected(ComponentName name) { }
}, Context.BIND_AUTO_CREATE);
如果是用StartService调用,两个都被调用到
Intent intent = new Intent("com.example.sharefiles.services.ShareServices.Test");
intent.setClass(getApplicationContext(), HttpWebService.class);
intent.putExtra("enable", true);
this.startService(intent);
查看google 文档
http://developer.android.com/reference/android/app/Service.html
onStart(Intent intent, int startId)
onStartCommand(Intent, int, int) instead.onStartCommand(Intent intent, int flags, int startId)
startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.鉴于目前的代码基本都是运行在API5 以上的,所以直接干掉onStart.
Service 中的 onStart 和 onStartCommand的更多相关文章
- android中activity向service中传值
和activity中互相传值类似 在activity中 Intent regIntent = new Intent(this, ChatService.class); regIntent.putEx ...
- 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信
Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...
- Windows Service中使用Threading.Timer需注意回收
在Windows Service中使用Threading.Timer时需要注意回收池问题 Threading.Timer是基于线程池的,系统会对其进行垃圾回收. 当Threading.Timer定义在 ...
- 关于Service中bindService注意的几个问题
最近有用到Activity需要不断的从Service中获取数据,第一个想法肯定就是通过bind回调机制了,有几点概念模糊特此记录下: 单独使用bindService(),unbindService() ...
- Android悬浮框,在Service中打开悬浮窗;在Service中打开Dialog;
文章介绍了如何在Service中显示悬浮框,在Service中弹出Dialog,在Service中做耗时的轮询操作: 背景需求: 公司的项目现在的逻辑是这样的:发送一个指令,然后3秒一次轮询去查询这个 ...
- 宿主在Windows Service中的WCF(创建,安装,调用) (host到exe,非IIS)
1. 创建WCF服务 在vs2010中创建WCF服务应用程序,会自动生成一个接口和一个实现类:(IService1和Service1) IService1接口如下: using System.Ru ...
- Service stopSelf(int statId)和onStartcommand(Intent intent,int flags,int startId)
Stopping a service A started service must manage its own lifecycle. That is, the system does not sto ...
- Handler: Service中使用Toast
Handler 的使用在 android App 开发中用的颇多,它的作用也很大,使用 Handler 一般也会使用到多线程,相信大家对 Handler 不会陌生,在这里,重点说一下 android ...
- 如何托管ASP.NET Core应用到Windows Service中
(此文章同时发表在本人微信公众号"dotNET开发经验谈",欢迎右边二维码来关注.) 题记:正在构思一个中间件的设计,考虑是否既可以使用最新的技术,也可以兼顾传统的部署模式.所以有 ...
随机推荐
- hadoop三种运行模式
1.单机模式:安装简单,几乎不用做任何配置,但仅限于调试用途 2.伪分布模式:在单节点上同时启动namenode.datanode.jobtracker.tasktracker.secondaryna ...
- Tomcat服务器配置https双向认证(使用keytool生成证书)
一,HTTPS原理 1,HTTP.HTTPS.SSL.TLS介绍与相互关系 (1)HTTP:平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的(明文),因此使用HTTP协议传输隐私 ...
- java并发之如何解决线程安全问题
并发(concurrency)一个并不陌生的词,简单来说,就是cpu在同一时刻执行多个任务. 而Java并发则由多线程实现的. 在jvm的世界里,线程就像不相干的平行空间,串行在虚拟机中.(当然这是比 ...
- 详解SpringMVC中Controller的方法中参数的工作原理
Spring MVC中Controller的处理方法的参数可以是Integer,String,自定义对象,ServletRequest,ServletResponse,ModelAndView等等,非 ...
- Tensorflow 之finetune微调模型方法&&不同层上设置不同的学习率
在不同层上设置不同的学习率,fine-tuning https://github.com/dgurkaynak/tensorflow-cnn-finetune ConvNets: AlexNet VG ...
- 使用JDBC在MySQL数据库中快速批量插入数据
使用JDBC连接MySQL数据库进行数据插入的时候,特别是大批量数据连续插入(10W+),如何提高效率呢? 在JDBC编程接口中Statement 有两个方法特别值得注意: void addBatch ...
- Duplicate复制数据库并创建物理StandBy(pfile版本)
1设定环境如下: Primary数据库 IP 172.17.22.16 SID orcl Standby数据库 IP 172.17.22.17 SID orcl 设置提示,以区分操作的位置 prima ...
- 用MATLAB生成模糊控制离线查询表
实时采样得到的数据经过模糊化处理后输入机器,通过查询模糊规则表便可得到应有的输出模糊量,从而避免了近似推理过程.实际应用中,特别是在控制系统较为简单而采用单片机控制时,常常采用这种查表法. 模糊控制表 ...
- Redis系列--内存淘汰机制(含单机版内存优化建议)
https://blog.csdn.net/Jack__Frost/article/details/72478400?locationNum=13&fps=1 每台redis的服务器的内存都是 ...
- 关于ř与tableau的集成---- k均值聚类
1.利用R内置数据集iris: 2.通过Rserve 包连接tableau,服务器:localhost,默认端口6311: 3.加载数据集iris: 4.编辑字段:Cluster <span s ...