入门异步任务之Handler

效果图如下:

 


 1、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lesson"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="7" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 2、activity_main.xml
 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="18dp"
        android:text="加载图片" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        
        />

</RelativeLayout>

 3、MainActivity.java

package com.lesson;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
	private Button button;
	private ProgressDialog progerssDialog;
	private ImageView imageView;//要加载的图片
	private int Thread1=1;
	private final String url="http://pic.4j4j.cn/upload/pic/20130701/d363891105.jpg";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);		
		button=(Button)findViewById(R.id.button1);
		imageView=(ImageView)findViewById(R.id.imageView1);
		
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
				//加载图片时的进度显示对话框
				progerssDialog=new ProgressDialog(MainActivity.this);
				progerssDialog.setTitle("loading");
				progerssDialog.setMessage("正在加载中...");
				
				//设置进度条水平加载
				progerssDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
				progerssDialog.show();
				//添加子线程,用于发送消息给主线程
			
				new Thread(new MyThread(url,Thread1,new MyHandler())).start();
			}
		});
	}
	
	
	class MyHandler extends Handler{
		@Override
		public void handleMessage(Message msg) {
			
			super.handleMessage(msg);
			if(msg.what==Thread1){
				imageView.setImageBitmap((Bitmap)msg.obj);
				progerssDialog.dismiss();
			}
		}
	}
	class MyThread implements Runnable{
		//声明用来标识url地址参数的变量
		private String url;
		//声明用来标识线程id的变量
		private int threadId=0;
		
		private Handler handler=null;
		
		//构造函数
		public MyThread(String url,int threadId,Handler handler){
			this.url=url;
			this.threadId=threadId;
			this.handler=handler;
		}
		@Override
		public void run() {
		
			HttpGet httpGet=new HttpGet(url);
			InputStream inputStream;
			byte[] result=null;
			byte[] data=new byte[1024];
			HttpClient client = new DefaultHttpClient();
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			try {
				HttpResponse httpResponse=client.execute(httpGet);//得到响应
				if(httpResponse.getStatusLine().getStatusCode()==200){
					
					inputStream=httpResponse.getEntity().getContent();
					//文件总长度
					int filelenth=(int) httpResponse.getEntity().getContentLength();
					int readlength=0;
					int totallenth=0;
					while((readlength=inputStream.read(data))!=-1){
						totallenth+=readlength;
						int progressValue= (int)((totallenth/(float)filelenth)*100);
						Log.i("progressValue",progressValue+"");
						
						progerssDialog.setProgress(progressValue);
						outputStream.write(data, 0, readlength);
					}
					result=outputStream.toByteArray();
					
					//向handler发送消息
					 	Message msg = new Message();  
				        msg.what = threadId;  
				        Bitmap bitmap=BitmapFactory.decodeByteArray(result, 0, result.length);
				        msg.obj=bitmap;
				        handler.sendMessage(msg);  
				}
				
			} catch (ClientProtocolException e) {
				
				e.printStackTrace();
			} catch (IOException e) {
				
				e.printStackTrace();
			}finally{
				client.getConnectionManager().shutdown();
			}
		}
		
	}
}

 注:ProgressDialog加载几种方式及注意点

// 方式一:new Dialog
		final ProgressDialog dialog = new ProgressDialog(this);
		dialog.show();

 

	// 方式二:使用静态方式创建并显示,这种进度条只能是圆形条,设置title和Message提示内容
		ProgressDialog dialog2 = ProgressDialog.show(this, "提示", "正在登陆中");

 

	// 方式三 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数boolean indeterminate设置是否是不明确的状态
		ProgressDialog dialog3 = ProgressDialog
				.show(this, "提示", "正在登陆中", false);

 

	// 方式四 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数boolean cancelable 设置是否进度条是可以取消的
		ProgressDialog dialog4 = ProgressDialog.show(this, "提示", "正在登陆中",
				false, true);

 

 

	// 方式五 使用静态方式创建并显示,这种进度条只能是圆形条,这里最后一个参数 DialogInterface.OnCancelListener
		// cancelListener用于监听进度条被取消
		ProgressDialog dialog5 = ProgressDialog.show(this, "提示", "正在登陆中", true,
				true, cancelListener);
服务器centos上安装IC618(virtuoso)教程 只需要按照提供的步骤即可实现IC618安装。有需要详情请联系QQ:563962386 阅读详情

相关推荐

STM32F103C8T6 Bootloader开发实战:串口IAP固件升级与Keil工程配置详解

本文详细介绍了STM32F103C8T6 Bootloader开发实战,重点讲解串口IAP固件升级的实现方法与Keil uVision5工程配置。通过Flash分区管理、USART1通信协议设计及应用程序跳转机制等核心技术,帮助开发者掌握嵌入式系统固件升级方案,提升设备维护效率。

weixin_29165725的博客 436

《第二十五章 多线程与异步任务 - Handler 消息处理机制》

Handler 主要用于发送和处理消息,而 Looper 则用于管理消息循环。在 Android 中,每个线程都可以有自己的消息循环,但 UI 线程默认已经有一个 Looper 在运行。Handler 消息处理机制是 Android 开发中实现多线程协作和异步任务的重要工具。理解 Handler 与 Looper 的关系、消息队列的工作原理以及消息的发送方式,能够帮助我们构建出高效、稳定且线程安全的应用程序。

weixin_47266126的博客 922

Halcon 3D点云处理实战:从PLY文件读取到曲面匹配的完整流程(附避坑指南)

本文详细介绍了Halcon在3D点云处理中的完整流程,从PLY文件读取到曲面匹配,特别强调了3D算子的应用技巧和避坑指南。通过实战案例和参数优化建议,帮助开发者高效处理工业视觉检测中的复杂点云数据,提升匹配精度和性能。

weixin_42535720的博客 278

Android(6)——Handler,异步任务

文章目录Android1 Handler1.1 概念1.2 Handler使用1.3 Handler 存在的问题1.4 Handler实践的三种效果2 异步任务2.1 AsyncTask2.2 网络下载demo Android 安卓开发者指南:https://developer.android.google.cn/guide 1 Handler 1.1 概念 1.Handler:消息分发对象,进行发送和处理消息,并且其Runable对象和一个线程的MessageQueue关联。 2.为什么要使用Handle

weixin_45044097的博客 838

实用工具系列 - Xshell安装下载与使用

一、介绍 二、下载 三、安装 四、使用

Passerby_Wang的博客 1万+

线性模型:AR、MA、ARMA、ARMAX、ARX、ARARMAX、OE、BJ等

线性模型:AR、MA、ARMA、ARMAX、ARX、ARARMAX、OE、BJ等

zephyr_wang的博客 1万+

android的异步任务与handler分析与初步实战

android的异步任务与handler分析

ShiXinXin_Harbour的博客 860

OCSP环境搭建--Windows Server 2016

OCSP环境搭建--Windows Server 2016 一. OCSP环境中相关信息 1. 服务器1 操作系统:Win Server 2016 Standard版 IP地址:172.16.0.19/23,网关:172.16.0.1,首选DNS:127.0.0.1 服务器角色:域控制器、证书颁发机构、radius服务器、DNS服务器 ...

CsdnCHong_566的博客 3351

Android多线程及异步任务消息处理机制(一)--Handler的使用

转载请注明出处: 前言         我们知道,不管在任何的语言或操作系统平台(Android系统也不例外),多线程、多进程和异步任务的相关技术地讨论都是永恒的话题,很多的开发需求都需要使用多线程及异步任务以便实现多任务的同时执行和灵活的用户操作界面,而很多系统在使用过程中出现诸多莫名其妙的问题,都是由于开发人员使用多线程不当造成的,因此掌握在各个平台上的多线程及异步任务的原

叶功恒的博客专栏 6653

DolphinScheduler租户配置踩坑实录:手把手教你修复‘tenant not exists‘报错

本文深度解析DolphinScheduler的租户模型,并提供一套从界面到数据库的系统性排查流程,手把手教你修复常见的'tenant not exists'报错。文章揭示了该错误的本质是用户与租户数据关联不一致,并给出了通过UI或SQL更新的具体修复方案,同时分享了根因分析与预防措施,帮助用户从根本上理解和避免此类问题。

2w3e4r5t6y的博客 541

VMware系列:此平台不支持虚拟化 Intel-VT-x/EPT 或 AMD-V/RVI

VMware系列:此平台不支持虚拟化 Intel-VT-x/EPT 或 AMD-V/RVI

weixin_54626591的博客 1万+

handler与异步任务

不知道为什么,刚才写的安卓下的事件监听会待审核,好吧,只是为了记录下我的学习状态而已 接下来说说安卓下的线程安全的问题 安卓的主线程是不允许用户将耗时的事情放在主线程中进行处理的,因为这样容易造成线程的不安全 线程安全:在java中,线程的安全就是指,例如有两个线程同时在操作同一个ArrayList的时候,我们都 知道,在add方法的时候,分两步,第一步是增加数据,第二步是增加元素的个数,那

爱吃青菜的鱼 665

YOLO26 改进 - 注意力机制 | Mask Attention掩码注意力,可学习掩码矩阵破解低分辨率特征提取难题 | 2025 预印

本文提出了用于低分辨率图像分割的MaskAttn - UNet框架,并将其核心的掩码注意力机制集成到YOLO26中。传统U - Net类模型难以捕捉全局关联,Transformer类模型计算量大,而掩码注意力机制通过可学习的掩码,让模型选择性关注重要区域,融合了卷积的局部效率和注意力的全局视野。其工作流程包括特征适配、掩码生成、定向注意力计算和特征融合。我们将掩码注意力机制代码集成到YOLO26中。

魔改工程师的博客 834

netty入门,入门代码执行流程,netty主要组件的理解

入门 netty底层采用多路复用技术,是异步的。底层也是采用的NIO。 入门代码 要使用netty,第一步当然是导入坐标 <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.39.Final</version> </dependency> 然后创建服务器端的代码

qq_44027353的博客 897

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

[转]Android异步处理系列文章索引

转载自:http://blog.youkuaiyun.com/mylzc/article/details/6777767 mark   为了给用户带来良好的交互体验,在Android应用的开发过程中需要把繁重的任务(IO,网络连接等)放到其他线程中异步执行,达到不阻塞UI的效果。 本系列文章由浅入深介绍Android进行异步处理的实现方法和系统底层的实现原理。   Android异步处理一:使...

suflow 225

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Android异步处理系列文章索引

本博文地址:http://blog.youkuaiyun.com/mylzc/article/details/6777767 转载请注明出处。 为了给用户带来良好的交互体验,在Android应用的开发过程中需要把繁重的任务(IO,网络连接等)放到其他线程中异步执行,达到不阻塞UI的效果。 本系列文章由浅入深介绍Android进行异步处理的实现方法和系统底层的实现原理。 Andro

kan1kan5的专栏 535

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android 异步处理

为了给用户带来良好的交互体验,在Android应用的开发过程中需要把繁重的任务(IO,网络连接等)放到其他线程中异步执行,达到不阻塞UI的效果。 本系列文章由浅入深介绍Android进行异步处理的实现方法和系统底层的实现原理。 Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面 (入门) 介绍如何使用Thread+Handler的方式从非UI线程发送界面更新...

weixin_34008784的博客 76

Handler 同步屏障&异步消息

简单来说,同步屏障就是一套为了让特殊消息更快执行的一个机制。这里我们假设一个场景:我们向主线程发送了一个UI绘制操作Message,而此时消息队列中的消息非常多,那么这个Message的处理可能会得到延迟,绘制不及时造成界面卡顿。同步屏障机制的作用,是让这个绘制消息得以越过其他的消息,优先被执行。MessageQueue中的Message,有一个变量,他标志了这个Message是否是异步消息;标记为true称为异步消息,标记为false称为同步消息。同时还有另一个变量target。

Pumpkin's Blog 1146

Android 异步任务的6种实现方式详解

Android 异步任务的6种实现方式详解 Android UI线程(主线程)有几个特点: 只能在 UI 线程操作 UI 视图,不能在子线程中操作。 不能在 UI 线程中进行耗时操作,否则会阻塞 UI 线程,引起 ANR、卡顿等问题。 在 Android 开发中,我们通常将一些耗时的操作使用异步任务的方式进行处理。例如这样一种这种场景,子线程在后台执行一个异步任务,任务过程中,需要 UI 进程展示进度,这时我们就需要一个工具来实现这种需求。Android 系统为开发人员提供了一个异步任务类(Async

卜大爷的博客 4万+

Android异步任务机制—Handler

介绍熟悉Windows编程的朋友知道Windows程序是消息驱动的,并且有全局的消息循环系统。Google参考了Windows的消息循环机制,也在Android系统中实现了消息循环机制。 Android的消息循环是针对线程的,每个线程都可以有自己的消息队列和消息循环。Handler机制主要角色Message:消息,其中包含了消息ID,消息处理对象以及处理的数据等,由MessageQueue统一列队

程序病毒小队的博客 554

Android 异步任务的三种方式:AsyncTask,Handler+Thread,RxJava

Android 耗时任务需要在子线程中进行,开启异步任务有三种方式

Alpinist Wang 2552
上一篇: 入门android异步任务之AsyncTask(以加载网络图片为例子)
下一篇: 入门android广播简单例子
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值