Service api
来源:互联网 发布:咸阳软件培训学校 编辑:程序博客网 时间:2024/06/08 06:45
public int onStartCommand (Intent intent, int flags, int startId)
Added in API level 5
调用startService(Intent)启动service的时候,onStartCommand会被系统回调。回调参数Intent为startService(Intent)中的参数,和一个用来表示这次请求的整数token。不要直接调用次方法。
为了向后兼容,默认实现了onStart(Intent,int)并且返回 START_STICKY
or START_STICKY_COMPATIBILITY
.
如果你的应用是运行在level 5 之前的,你可以仿照下面的处理方法。onStartCommand(Intent intent, int flags, int startId)方法在level 5后面的系统中被调用。
// This is the old onStart method that will be called on the pre-2.0// platform. On 2.0 or later we override onStartCommand() so this// method will not be called.@Overridepublic void onStart(Intent intent, int startId) { handleCommand(intent);}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) { handleCommand(intent); // We want this service to continue running until it is explicitly // stopped, so return sticky. return START_STICKY;}
注意:上面的方法是在service的主线程中被调用的。service的主线程为ui线程。你应该避免主线程的事件循环被阻塞.当处理长时间的操作,网络交互,或大量磁盘io的操作的时候,应该用一个新的线程,或使用AsyncTask;
Parameters
START_FLAG_REDELIVERY
, or START_FLAG_RETRY
.Returns
- The return value indicates what semantics the system should use for the service's current started state. It may be one of the constants associated with the
START_CONTINUATION_MASK
bits. - 返回值表明系统如何处理当前启动的service的启动状态。返回值可能与START_CONTINUATION_MASK位相关的常量。
See Also
stopSelfResult(int)
- Service api
- JSON Service API
- service API and 翻译
- [翻译]API Guides - Service
- service [翻译]API Guides
- Service API文档 翻译
- Service API Guides
- Odoo Web Service API
- Windows API 之 Windows Service
- Android 2.2 API Demos -- Service
- web service与web api
- android api分析21 Service
- android api分析22 Service
- Android Api Component---翻译Service
- Android API 指南 - 【服务 Service】
- (API GUIDE 5)Service(服务)
- [API GUIDE学习笔记]Service
- Nitrate XML-RPC Service API
- js JAvaWEb ssh struts hibernate spring js 和java对比
- openjdk和jdk的区别与联系
- 小结-vmware Linux与windows配置 host-only
- java之IO
- 杭电ACM。。。sort
- Service api
- 关于firefox安全限制限制您进行剪贴板操作的解决方法
- C语言调用Lua脚本
- 4_2
- socket http通信
- JAVA正则表达式 Pattern和Matcher详解
- 在STK里使用飞机任务模块
- freeswitch
- 杂记