IntentService的用法,对比Service它会按顺序执行,不会像Service一样并发执行。
package com.lixu.intentservice; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<20;i++){
Intent intent=new Intent(this,MyAppService.class);
intent.putExtra(Changliang.KEY, i+""); startService(intent);
}
}
//不要忘了关闭服务
@Override
protected void onDestroy() {
Intent intent=new Intent(this,MyAppService.class);
stopService(intent);
super.onDestroy();
} }
package com.lixu.intentservice; import android.app.IntentService;
import android.content.Intent;
import android.util.Log; public class MyAppService extends IntentService{
//构造方法要修改
public MyAppService() {
super("lixu");
} @Override
protected void onHandleIntent(Intent intent) { String str=intent.getStringExtra(Changliang.KEY);
Log.e("MyAppService","内容"+ str);
int content=0;
final int A=content++;
Log.e("MyAppService","线程"+ A+"开始执行");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("MyAppService", "线程"+ A+"结束"); } }
IntentService的用法,对比Service它会按顺序执行,不会像Service一样并发执行。的更多相关文章
- Android开发--IntentService的用法,你错过了什么
Android开发--IntentService的用法,你错过了什么 . 本文链接:https://blog.csdn.net/smbroe/article/details/45009721 Inte ...
- Android学习总结(三)——IntentService的用法
一.IntentService的基本概念 IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentServi ...
- Windows Azure Service Bus (6) 中继(Relay On) 使用VS2013开发Service Bus Relay On
<Windows Azure Platform 系列文章目录> 注意:本文介绍的是国内由世纪互联运维的Windows Azure服务. 项目文件请在这里下载. 我们在使用Azure平台的时 ...
- delphi调用web service出现 Unable to retrieve the URL endpoint for Service/Port .....
delphi调用web service出现 Unable to retrieve the URL endpoint for Service/Port, 错误截图如下 查了很长时间, 发现在DataM ...
- 最新cenos执行service httpd restart 报错Failed to restart httpd.service: Unit not found.
原来是需要将Apache注册到Linux服务里面啊!注册Apache到Linux服务在Linux下用源代码方式编译安装完Apache后,启动关闭Apache可以通过如下命令实现: /usr/local ...
- Service具体解释(一):什么是Service
< Service具体解释(一):什么是Service> < Service具体解释(二):Service生命周期> <Service具体解释(三):Service的使用 ...
- Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details. To force a start use "systemctl reset-failed
安装docker时,自己添加了国内的hub.docker.com镜像 [root@ce-docker ~]# systemctl restart docker 出现以下报错:Job for docke ...
- javascript中call,apply,bind的用法对比分析
这篇文章主要给大家对比分析了javascript中call,apply,bind三个函数的用法,非常的详细,这里推荐给小伙伴们. 关于call,apply,bind这三个函数的用法,是学习java ...
- Linq表达式和Lambda表达式用法对比
什么是Linq表达式?什么是Lambda表达式?前一段时间用到这个只是,在网上也没找到比较简单明了的方法,今天就整理了一下相关知识,有空了再仔细研究研究 public Program() { List ...
随机推荐
- 【javascript】数据结构-链表
// 创建一个链表 function LinkedList(){ // 创建一个Node辅助类,表示需要加入列表的项,它包含一个element属性,即表示需要加入到列表中的值,next属性表示指向下一 ...
- Java 多线程中的任务分解机制-ForkJoinPool,以及CompletableFuture
ForkJoinPool的优势在于,可以充分利用多cpu,多核cpu的优势,把一个任务拆分成多个“小任务”,把多个“小任务”放到多个处理器核心上并行执行:当多个“小任务”执行完成之后,再将这些执行结果 ...
- Zookeeper 概念
Zookeeper: Zookeeper是一个高可用的分布式管理与协调框架,基于ZAB算法(原子消息广播协议)的实现.该框架能够很好的保证分布式环境中数据的一致性.也只是基于这样的特性,使得Zooke ...
- 32位MD5加密补齐丢失的0
/// <summary> /// 获取32位MD5加密字符串(已补完0) /// </summary> /// <param name="strWord&qu ...
- Inversion of Control Containers and the Dependency Injection pattern
https://martinfowler.com/articles/injection.html One of the entertaining things about the enterprise ...
- java代码实现highchart与数据库数据结合完整案例分析(二)---折线图
作者原创:未经博主允许不许转载 在上一篇的博客中,展示和分析了如何做一个饼状图,有疑问可以参考上一篇博客. 现在分析和展示折线图的绘制和案例分析, 先展示效果图: 与饼状图不同的是,折线图展现更多的数 ...
- The way to Go(7): 变量
参考: Github: Go Github: The way to Go 变量 一般格式:var identifier type. Go在声明变量时将变量的类型放在变量的名称之后: 避免像 C 语言中 ...
- Spirng boot 启动的时候进行监控检查不通过停止服务与自定义健康监控节点
基于 spring-boot-starter-actuator • 前提条件: <dependency> <groupId>org.springframework.bo ...
- UVa 12174 Shuffle(滑动窗口)
https://vjudge.net/problem/UVA-12174 题意: 你在听音乐播放器,它采用随机播放形式.随机播放的原理时先随机产生一个1~n的排列,然后就按这个排列顺序播放歌曲.播放完 ...
- .NET反射的优化
写在前面 1)本篇博客并非原创,而是我针对.NET反射相关知识的总结.本篇内容来源汇总于3篇博客.在后面的介绍中会在开头给出对应的链接,方便读者自行学习.2)本篇博客主要针对表达式树代码进行详细讲解. ...