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一样并发执行。的更多相关文章

  1. Android开发--IntentService的用法,你错过了什么

    Android开发--IntentService的用法,你错过了什么 . 本文链接:https://blog.csdn.net/smbroe/article/details/45009721 Inte ...

  2. Android学习总结(三)——IntentService的用法

    一.IntentService的基本概念 IntentService是继承于Service并处理异步请求的一个类,在IntentService内有一个工作线程来处理耗时操作,启动IntentServi ...

  3. Windows Azure Service Bus (6) 中继(Relay On) 使用VS2013开发Service Bus Relay On

    <Windows Azure Platform 系列文章目录> 注意:本文介绍的是国内由世纪互联运维的Windows Azure服务. 项目文件请在这里下载. 我们在使用Azure平台的时 ...

  4. 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 ...

  5. 最新cenos执行service httpd restart 报错Failed to restart httpd.service: Unit not found.

    原来是需要将Apache注册到Linux服务里面啊!注册Apache到Linux服务在Linux下用源代码方式编译安装完Apache后,启动关闭Apache可以通过如下命令实现: /usr/local ...

  6. Service具体解释(一):什么是Service

    < Service具体解释(一):什么是Service> < Service具体解释(二):Service生命周期> <Service具体解释(三):Service的使用 ...

  7. 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 ...

  8. javascript中call,apply,bind的用法对比分析

    这篇文章主要给大家对比分析了javascript中call,apply,bind三个函数的用法,非常的详细,这里推荐给小伙伴们.   关于call,apply,bind这三个函数的用法,是学习java ...

  9. Linq表达式和Lambda表达式用法对比

    什么是Linq表达式?什么是Lambda表达式?前一段时间用到这个只是,在网上也没找到比较简单明了的方法,今天就整理了一下相关知识,有空了再仔细研究研究 public Program() { List ...

随机推荐

  1. HDU1143 (递推)题解

    Tri Tiling Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  2. hdu 3874(树状数组)题解

    Problem Description Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ba ...

  3. ubuntu 安转redis

    一 ,redis 安装配置 在 Ubuntu 系统安装 Redis 可以使用以下命令: sudo apt-get update sudo apt-get install redis-server 这样 ...

  4. Change the Forwarding: RMT Architecture

    Change the Forwarding: RMT Architecture Note on "Forwarding Metamorphosis: Fast Programmable Ma ...

  5. Ubuntu 下 su:authentication failure的解决办法

    Ubuntu下使用 su 切换到超级用户时候遇到下面的问题 su: Authentication failure 解决办法: $ sudo passwd root Enter new UNIX pas ...

  6. java中Scanner类nextInt之后用nextLine无法读取输入

    http://blog.csdn.net/wjy1090233191/article/details/42080029 这篇文章写得非常详细和准确

  7. python flask 接口

    例子1 from flask import Flask, jsonify app = Flask(__name__) tasks = [ { , 'title': u'Buy groceries', ...

  8. robot_pose的类型

    http://docs.ros.org/api/geometry_msgs/html/msg/Pose.html

  9. python 压缩tar 包

    import tarfile import os def make_targz(output_filename, source_dir): print("doing!") with ...

  10. python学习——大文件分割与合并

    在平常的生活中,我们会遇到下面这样的情况: 你下载了一个比较大型的游戏(假设有10G),现在想跟你的同学一起玩,你需要把这个游戏拷贝给他. 然后现在有一个问题是文件太大(我们不考虑你有移动硬盘什么的情 ...