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 ...
随机推荐
- python中command执行shell命令脚本方法
在Python中有一个模块commands也很容易做到以上的效果.看一下三个函数:1). commands.getstatusoutput(cmd)用os.popen()执行命令cmd, 然后返回两个 ...
- Ansible 入门指南 - ansible-playbook 命令
上篇文章Ansible 入门指南 - 安装及 Ad-Hoc 命令使用介绍的额是 Ad-Hoc 命令方式,本文将介绍 Playbook 方式. Playbook 译为「剧本」,觉得还挺恰当的. play ...
- 客户端向服务端请求连接是出现"ssh : Connection refused"原因有哪些
注意:服务端的sshd服务已经正常开启 (可以正常进行连接) 1.在服务端负载比较高的情况下客户端请求连接时会出现连接被拒绝的情况
- AlexNet网络结构特点总结
参考论文:ImageNet Classification with Deep Convolutional Neural Networks 1.特点 1.1 ReLU Nonlinearity的提出 Re ...
- 进制转换 hdoj-2031
进制转换,原题目:hdoj-2031 题目描述: 输入两个整数,十进制数n(32位整数)和进制r(2<=r<=16 r!=10),求转换后的数. 输入: 7 2 23 12 -4 3 输出 ...
- 软件测试&安全测试高峰论坛
Nubia测试以及介绍 基于Cucumber的自动化测试平台 常见Web漏洞之XSS,主要HTML与JS基础.XSS的基础知识与挖掘方法.XSS的利用 自动化测试框架以及测试思路
- shell case语句
case 格式 case 值 in 模式1) command1 command2 ... commandN ;; 模式2) command1 command2 ... commandN ;; esac ...
- 安装cartographer
# Build and install Cartographer. git clone https://github.com/hitcm/cartographer.git cd cartographe ...
- Spring Boot 2.1.1.RELEASE 多数据源配置与使用
有时候,一个系统的功能,需要两个或两个以上的数据库, 在Spring Boot 中要如何配置? How to? #primary primary.spring.datasource.jdbc-url= ...
- maven 下载不到jar包时候,更改阿里源
maven 源 下载太慢,更改国内的阿里源会快一些 <repositories> <repository> <id>alimaven</id> &l ...