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开发经验谈",欢迎右边二维码来关注.) 题记:正在构思一个中间件的设计,考虑是否既可以使用最新的技术,也可以兼顾传统的部署模式.所以有 ...
随机推荐
- 我定制的Stylish样式
没有办法上传,只好存到这里. 天涯 .atl-con-ft, .js-zhiyin-area, .ds_seat_foot, .hongbao-btn, .dashang-left-btn, .qrc ...
- nagle算法和TCP_NODELAY
写socket发现的一个诡异现象,当时将多个小数据写操作合并成一个写操作,问题就没了.Chenshuo同学还建议我设置TCP_NODELAY,只是后来因为事情忙,也就没有再深究下去. 现在大概明白,是 ...
- AngularJS中实现Model缓存
在AngularJS中如何实现一个Model的缓存呢? 可以通过在Provider中返回一个构造函数,并在构造函数中设计一个缓存字段,在本篇末尾将引出这种做法. 一般来说,Model要赋值给Scope ...
- Delphi不注册COM直接使用ActiveX控件并绑定事件
文笔不行,直接上源码: 主窗口: unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System ...
- 版本控制-GitHub
前面几篇文章,我们介绍了Git的基本用法及Git服务器的搭建,本篇文章来学习一下如何使用GitHub.GitHub是开源的代码库以及版本控制库,是目前使用网络上使用最为广泛的服务,GitHub可以托管 ...
- 从YOLOv1到YOLOv3,目标检测的进化之路
https://blog.csdn.net/guleileo/article/details/80581858 本文来自 CSDN 网站,作者 EasonApp. 作者专栏: http://dwz.c ...
- GIS中栅格数据结构的显示与计算
在GIS中,根据数据存储的表现形式不同,通常将空间数据分为矢量数据和栅格数据.最简单的区别是:当栅格数据放大到一定程度时,就会呈现出我们熟悉的讨厌的"马赛克". 栅格数据存储 最简 ...
- 为什么用svg放弃了iconfont?
svg替代iconfont的好处(无论是基于Vue.Jquery),都推荐svg http://www.woshipm.com/pd/463866.html svg图标库,svg图标在线制作 http ...
- MDX Cookbook 03 - MDX 查询中负数,零和空值 NULL 的格式化处理
FORMAT_STRING 属性在处理计算成员(通常是度量值成员)的时候会经常使用到,比如指定标准 Standard, 货币 Currency 或者 Percent 百分比格式.除此之外,还可以自定义 ...
- NPM慢怎么办 - nrm切换资源镜像
1. 直接配置为taobao镜像 npm config set registry https://registry.npm.taobao.org 1. 使用NRM管理镜像 npm isntall -g ...