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. MFC、Qt、C#跨线程调用对象

    MFC.Qt.C#都是面向对象的编程库 1.MFC不允许跨线程调用对象,即线程只能调用它本身分配了空间的对象 In a multi-threaded application written using ...

  2. 搭建最新版本的Android开发环境

    只为成功找方法,不为失败找借口! Android开发学习总结(一)——搭建最新版本的Android开发环境 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Andr ...

  3. linux下安装evernote国际版

    一.背景 由于之前一直将笔记记录在evernote,因此现在转到linux下需要使用工具来记录笔记到evernote上 OS : Ubuntu 16.04 (xenial) 二.linux版everp ...

  4. UVA 3942 Remember the Word (Trie+DP)题解

    思路: 大白里Trie的例题,开篇就是一句很容易推出....orz 这里需要Trie+DP解决. 仔细想想我们可以得到dp[i]=sum(dp[i+len[x]]). 这里需要解释一下:dp是从最后一 ...

  5. 【附7】turbine

    一.作用 聚集同一个微服务的相同的commandKey.Threadpool.commandGroupKey数据进行聚合 二.配置 1.集群(cluster)(turbine聚集数据的粒度) turb ...

  6. 【异常记录(11)】 Web应用程序项目 已配置为使用 IIS。无法访问 元数据库。您没有足够的特权访问计算机上的 IIS 网站

    解决办法: 1.项目上右键, 编辑 xxxx.csproj 2.找到  <UseIIS> 标签, 改为 <UseIIS>False</UseIIS> 3.右键,重新 ...

  7. .NET反射的优化

    写在前面 1)本篇博客并非原创,而是我针对.NET反射相关知识的总结.本篇内容来源汇总于3篇博客.在后面的介绍中会在开头给出对应的链接,方便读者自行学习.2)本篇博客主要针对表达式树代码进行详细讲解. ...

  8. Python的collections模块中的OrderedDict有序字典

    如同这个数据结构的名称所说的那样,它记录了每个键值对添加的顺序. ? 1 2 3 4 5 6 d = OrderedDict() d['a'] = 1 d['b'] = 10 d['c'] = 8 f ...

  9. React Native之进度条ProgressViewIOS的使用

    import React,{Component}from 'react'; import { AppRegistry, StyleSheet, Text, View, ProgressViewIOS, ...

  10. Linux——vim/vi 简单学习笔记

    Vim/Vi是一个功能强大的全屏幕文本编辑器,是Linux/UNIX上最常用的文本编辑器,它的作用是建立.编辑.显示文本文件.Vim/Vi 没有菜单,只有命令. 早前也用过Vim变过C++/C的代码, ...