Service和IntentService
来源:互联网 发布:网络展示平台 编辑:程序博客网 时间:2024/06/07 05:36
关于普通service有两个点要注意:
Service不是一个单独的进程 ,它和应用程序在同一个进程中
Service不是一个线程,所以我们应该避免在Service里面进行耗时的操作
IntentService会构造一个工作线程,并在工作线程中执行onHandleIntent方法,在执行完毕后结束service。
IntentService官方文档中的用法
public class HelloIntentService extends IntentService { /** * A constructor is required, and must call the super IntentService(String) * constructor with a name for the worker thread. */ public HelloIntentService() { super("HelloIntentService"); } /** * The IntentService calls this method from the default worker thread with * the intent that started the service. When this method returns, IntentService * stops the service, as appropriate. */ @Override protected void onHandleIntent(Intent intent) { // Normally we would do some work here, like download a file. // For our sample, we just sleep for 5 seconds. long endTime = System.currentTimeMillis() + 5*1000; while (System.currentTimeMillis() < endTime) { synchronized (this) { try { wait(endTime - System.currentTimeMillis()); } catch (Exception e) { } } } }}
0 0
- Service和IntentService
- android Service和IntentService
- 关于IntentService和Service
- Service 和 IntentService
- IntentService和Service比较
- Service和IntentService
- Service和IntentService生命周期
- Service和IntentService
- Service和IntentService区别
- Service和IntentService区别
- Service和IntentService
- Service和IntentService
- Service 和 IntentService 的比较
- Service和IntentService的区别
- IntentService和Service的比较
- Android 中Service 和IntentService
- IntentService和Service高级应用
- Service和IntentService的区别
- 项目中的术语
- PAT 甲级 1068 Find More Coins(0,1背包)
- spark入门知识(一)
- kafka代码初步涉猎,用代码发送消息到客户端
- 原来,它可以用来展现营销文案!
- Service和IntentService
- Android Studio 报错:some files crunching failed,see logs for details
- HBase Shell 常用操作
- svn分支的代码合并到主干的步骤及注意
- Android 让EditText不自动获取焦点
- linux多文件压缩一个文件成tar.gz的命令
- 大型网站架构演化
- java 序列化学习
- ubuntu 源码安装apache和nginx