Android异步1:Thread+Handler更新UI

每个Android应用程序都运行在一个dalvik虚拟机进程中,进程开始的时候会启动一个主线程(MainThread),主线程负责处理和ui相关的事件,因此主线程通常又叫UI线程。而由于Android采用UI单线程模型,所以只能在主线程中对UI元素进行操作。如果在非UI线程直接对UI进行了操作,则会报错:

CalledFromWrongThreadException:only the original thread that created a view hierarchy can touch its views
。
Android为我们提供了消息循环的机制,我们可以利用这个机制来实现线程间的通信。那么,我们就可以在非UI线程发送消息到UI线程,最终让Ui线程来进行ui的操作。


对于运算量较大的操作和IO操作,我们需要新开线程来处理这些繁重的工作,以免阻塞ui线程。

例子:下面我们以获取ITEYE logo的例子,演示如何使用Thread+Handler的方式实现在非UI线程发送消息通知UI线程更新界面。


public class ThreadHandlerActivity extends Activity {
/** Called when the activity is first created. */

private static final int MSG_SUCCESS = 0;//获取图片成功的标识
private static final int MSG_FAILURE = 1;//获取图片失败的标识

private ImageView mImageView;
private Button mButton;

private Thread mThread;

private Handler mHandler = new Handler() {
public void handleMessage (Message msg) {//此方法在ui线程运行
switch(msg.what) {
case MSG_SUCCESS:
mImageView.setImageBitmap((Bitmap) msg.obj);//imageview显示从网络获取到的logo
Toast.makeText(getApplication(), getApplication().getString(R.string.get_pic_success), Toast.LENGTH_LONG).show();
break;

case MSG_FAILURE:
Toast.makeText(getApplication(), getApplication().getString(R.string.get_pic_failure), Toast.LENGTH_LONG).show();
break;
}
}
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView= (ImageView) findViewById(R.id.imageView);//显示图片的ImageView
mButton = (Button) findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if(mThread == null) {
mThread = new Thread(runnable);
mThread.start();//线程启动
}
else {
Toast.makeText(getApplication(), getApplication().getString(R.string.thread_started), Toast.LENGTH_LONG).show();
}
}
});
}

Runnable runnable = new Runnable() {

@Override
public void run() {//run()在新的线程中运行
HttpClient hc = new DefaultHttpClient();
HttpGet hg = new HttpGet("http://www.iteye.com/images/logo.gif");//获取iteye的logo
final Bitmap bm;
try {
HttpResponse hr = hc.execute(hg);
bm = BitmapFactory.decodeStream(hr.getEntity().getContent());
} catch (Exception e) {
mHandler.obtainMessage(MSG_FAILURE).sendToTarget();//获取图片失败
return;
}
mHandler.obtainMessage(MSG_SUCCESS,bm).sendToTarget();//获取图片成功,向ui线程发送MSG_SUCCESS标识和bitmap对象

// mImageView.setImageBitmap(bm); //出错!不能在非ui线程操作ui元素

// mImageView.post(new Runnable() {//另外一种更简洁的发送消息给ui线程的方法。
//
// @Override
// public void run() {//run()方法会在ui线程执行
// mImageView.setImageBitmap(bm);
// }
// });
}
};

}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/button" android:text="@string/button_name" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<ImageView android:id="@+id/imageView" android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>




为了不阻塞ui线程,我们使用mThread从网络获取了Iteye的LOGO,并用bitmap对象存储了这个Logo的像素信息。


此时,如果在这个线程的run()方法中调用


mImageView.setImageBitmap(bm)


会出现:CalledFromWrongThreadException:only the original thread that created a view hierarchy can touch its views。原因是run()方法是在新开的线程中执行的,我们上面提到不能直接在非ui线程中操作ui元素。


[size=large][b]非UI线程发送消息到UI线程分为两个步骤[/b][/size]

[b]一、发送消息到UI线程的消息队列[/b]


通过使用Handler的
Message obtainMessage(int what,Object object)


构造一个Message对象,这个对象存储了是否成功获取图片的标识what和bitmap对象,然后通过message.sendToTarget()方法把这条message放到消息队列中去。

[b]二、处理发送到UI线程的消息[/b]

在ui线程中,我们覆盖了handler的

public void handleMessage (Message msg)


这个方法是处理分发给ui线程的消息,判断msg.what的值可以知道mThread是否成功获取图片,如果图片成功获取,那么可以通过msg.obj获取到这个对象。
最后,我们通过



[java] view plaincopy
01.mImageView.setImageBitmap((Bitmap) msg.obj);

设置ImageView的bitmap对象,完成UI的更新。
Android异步加载数据更新UI(Thread+Handler) 目录:     1.异步加载应用场景+概述     2.Thread+Handler和AsyncTask实现异步对比     3.Thread+Handler异步加载图片(Demo) 1.异步加载应用场景+概述     异步加载主要应用于处理需要处理比较耗时的操作,有需要更新UI的场景,比如异步请求网络获取图片,或者其他数据时使用,好处     是在执行耗时操作时不影响用户的UI操 阅读详情

相关推荐

Android异步消息处理之Thread+Handler

Android Developers中Keeping Your App Response一文中: No response to an input event (such as key press or screen touch events) within 5 seconds.A BroadcastReceiver hasn't finished executing within 10 se

Run Away 2400

Android+Handler+Thread 那些事儿

  前言,才开始学安卓十几天,不料被线程挡住了前进的步伐,因为之前操作系统课程并没有认真听老师讲课,导致现在理解这些抽象的东西有些小困难。没关系,苦学之路,总会碰到坎坷,这里也给那些迷失在Android之路的小生们鼓励,每天多学一点,就是给自己最大的馈赠。   1.可能有很多人看到这个线程就有点慌乱了手脚,这个名词有点高大上,我是这么觉得的,无独有偶,我觉得同步,异步也是一...

SFC0511的博客 196

Android线程通信与UI更新:Handler机制详解

在Android开发中,线程通信是处理异步任务与UI更新的核心技术。系统通过消息循环机制实现线程间通信,其核心组件包括MessageQueue、Looper和Handler。这种设计解决了非UI线程直接操作UI组件导致的线程安全问题,同时避免了主线程阻塞引发的ANR(Application Not Responding)现象。Handler作为Android系统的基石,不仅支持传统的消息发送与处理,还提供了post方法简化Runnable的执行。现代开发中,虽然Kotlin协程和LiveData等新技术逐渐

weixin_30615767的博客 520

Android 多线程之HandlerThread 完全详解

转载请注明出处(万分感谢!): http://blog.youkuaiyun.com/javazejian/article/details/52334098 出自【zejian的博客】 关联文章: Android 多线程之HandlerThread 完全详解 Android 多线程之IntentService 完全详解   之前对线程也写过几篇文章,不过倒是没有针对android,因为java

zejian的博客 6万+

Android中利用Handler异步更新UI的示例

Handler是Android中用于处理线程间通信的一个重要组件。它允许你发送和处理Message和Runnable对象,通常与Looper类配合使用,实现线程间的通信。Handler主要用于更新UI,因为UI的操作在Android中是线程不安全的,所有UI操作必须在主线程中进行,而Handler则提供了在其他线程中发送消息到主线程的能力。

weixin_35752645的博客 1174

IMU卡尔曼滤波方法详细介绍

本文介绍了基于IMU和卡尔曼滤波的状态估计方法。系统采用9维状态向量(位置、速度、加速度计零偏),通过牛顿运动学建立状态方程,并利用外部位置观测进行校正。详细推导了状态转移矩阵和控制输入矩阵的形式,阐述了预测和更新的计算步骤。同时说明了过程噪声Q和观测噪声R的设置原则,其中Q反映模型不确定性,R取决于传感器精度。该方法可有效融合IMU测量与外部观测数据,实现位置、速度和偏置的联合估计。

haing2019的博客 757

【Android】Android中的线程(Thread+Handler)

之前po了一篇文章《【Android】Android中的线程(AsyncTask)》

爱臭美的程序猿 1104

语音识别(ASR)-- Kaldi 学习笔记

语音识别(ASR)-- Kaldi学习笔记语音识别简介GMM-HMM基本原理DNN-HMM(基于神经网络)KaldiKaldi架构简介Kaldi在Windows下的安装工具准备编译OpenFST配置PortAudio配置KaldiKaldi目录说明 语音识别简介 语音识别(Speech Recognition)技术,也被称为自动语音识别(Automatic Speech Recognition, ASR)、计算机语音识别(Computer Speech Recognition)或是语音转文本识别(Spee

qq_43318971的博客 4848

【移动开发】Android中异步加载数据(一)Handler + Thread

在我们开发当中很多时候都会遇到:从网络上获取数据的操作或大量的IO数据操作时,会耗费很长时间,为了使用户的体验效果更好,现在大多数开发者都会使用异步的方式去处理这些的操作,异步的方式有好多种,在此我汇总了以下两种: 1.Handler + Thread的方式 2.AsyncTask异步更新UI界面 这两种方式各自有各自的优缺点,这里先...

weixin_34101784的博客 183

PCL:SAC-IA+ICP配准

【代码】SAC-IA+ICP配准。

m0_71596228的博客 1018

RK3568 OpenHarmony3.2 NFC 驱动适配(PN7150)II

承接上文《RK3568 OpenHarmony3.2 NFC 驱动适配(PN7150)I》,继续PN7150 NFC模块的整体适配。本文主要介绍包括HDI实现层、框架层以及设备适配层的代码修改思路。具体包括vendor_adaptor、hdi_service等;以及foundation下的frameworks、services等。此外还包括相关三方库libnfc-nci在鸿蒙平台的移植和适配。需要注意的是,当前nfc适配只是基于作者手上的RK3568平台以及相关OpenHarmony3.2的代码。

Martian_Jonas的博客 1362

Android 进阶15:HandlerThread 使用场景及源码解析

眼睛困得要死,但今天的计划不完成又怎么能睡呢?明日复明日,明日何其多啊! 读完本文你将了解: HandlerThread 简介 HandlerThread 源码 HandlerThread 的使用场景 举个栗子 运行结果 总结 代码地址为了避免 ANR,我们常常需要在线程中做耗时操作,然后把结果抛到主线程进行处理。Android 提供了多种用于这种场景的组件,其中一种就是本篇文章要介绍的 Handl

张拭心的博客 shixinzhang 2万+

RK3588&RK3576实现 HW-ID DTB(动态加载不同的Kernel DTB)功能

RK平台的U-Boot⽀持检测硬件上的GPIO或者ADC状态动态加载不同的Kernel DTB,暂称为HW-ID DTB(Hardware id DTB)功能。

Wynter 849

Android线程问题解决——Thread+Handler的使用和AsyncTask的使用(外加安卓进度条的代码实现)

文章目录问题引入线程知识  主线程(UI线程)  子线程解决方案  一,使用Thread+Handler处理     1.概念     2.流程图     3.过程概述     4.代码实现  二,用AsyncTask处理     1.概念(异步执行的四个方法)     2.流程图     3.AsyncTask异步任务使用时的注意事项     4.AsyncTask异步任务代码实现进度条总结 问题引入  Android用户界面是与用户交互的接口,对于用户的操作,Android迅速响应用户输入(200ms内

qq_43107850的博客 3381

【测开求职】面试题:操作系统 吐血整理

本篇文章是笔者为准备研究生复试和校招而写,因此主要针对问答,注重理解,而不在于细节计算。涵盖考研范围内的所有知识内容,读者可以先查看上面的链接走一遍操作系统的整体框架结构。其中,重点难点以及易混淆的知识点,笔者用其他文章进行了详述,在知识点处贴好了链接,有需要的可以查阅。另外操作系统在校招中有非常明显的重点,一般情况下只会考察进程管理,内存管理,和设备管理,且这三者考察频率依次递减,文件管理基本不会考察。

vector的博客 7910

渗透测试工具之Sliver

攻击者需要将生成的植入物传输到目标系统,并执行它。C2 框架的架构与 Metasploit(如 Meterpreter)类似,但更专注于。(Red Teaming)中常见的攻击工具之一,攻击者利用 C2 服务器。组成,二者共同实现 C2 服务器与受控设备的通信。植入物(Implants)是 Sliver 生成的。抓包分析时,可以看到所有数据都是加密传输的。和**监听器(Listeners)**功能。Sliver 支持多种通信协议,如。随着安全防御的不断提升,企业应加强。进行通信,数据仍然是加密的。

idlecloud0105的博客 1936

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

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

Alpinist Wang 2552

手把手教你学simulink(95.1)--PID控制实例:基于Simulink的PID控制温度控制系统建模与仿真

温度控制是工业自动化、家用电器、医疗设备以及航空航天等领域中常见的控制问题。通过精确的温度控制,可以提高生产效率、降低能耗并确保产品质量。PID(比例-积分-微分)控制器因其结构简单、性能稳定且易于实现而被广泛应用于各种温度控制系统。本项目旨在通过MATLAB/Simulink平台设计和验证一个基于PID控制的温度控制系统,重点研究PID参数调优方法、系统动态响应特性以及稳态误差消除能力。

MHD0815的博客 793

Android Handler机制:异步消息处理与UI线程更新

在Android开发中,异步消息处理是解决耗时操作与UI更新矛盾的核心机制。其基本原理是通过Handler、Looper和MessageQueue构建跨线程通信桥梁,实现子线程任务完成后安全通知主线程更新界面。这种机制既避免了直接在UI线程执行耗时操作导致的界面卡顿,又防止了子线程直接操作UI引发的崩溃问题。从技术价值看,Handler机制提供了精细的消息优先级控制和时序管理能力,适用于网络请求回调、定时任务、跨进程通信等场景。特别是在电商倒计时、图片分块处理等需要精确控制消息顺序的场景中表现优异。结合消息

weixin_30471561的博客 407

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

安卓异步线程消息机制学习——Handler+Thread+Looper

前言:在安卓应用开发中面临着一个问题,如果应用在主线程(即UI线程)中进行网络通信的时候很有可能会造成主线程长时间阻塞,而阻塞超过5秒钟程序就会崩溃!自然可以考虑新建一个工作线程(Thread)来完成网络通信,那么问题又来了,譬如在完成了网络通信后往往需要更新UI,我们的网络通信是在子线程中完成的,而安卓的UI交互是在主线程中实现的!显然,我们无法在网络通信的子线程中更新UI。如果说子线程可以在自

JerryCQU的专栏 1075

深度学习工具包 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异步更新UI教程总结与demo

概述我们在Android开发中可能会遇到下面错误:Only the original thread that created a view hierarchy can touch its views意思是我们只能在主线程更新UI,我们知道UI线程(主线程)如果被阻塞5秒,就会ANR,所以我们耗时的操作都会新开启线程,这就必然涉及到后续的UI的更新,今天我们就来讨论下异步更新UI的使用方法总结。主要讲

Simon_Crystin的博客 1620

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【安卓笔记】Handler+Thread使用浅析

之前介绍了AsyncTask,今天介绍Handler+Thread的使用方式。 使用Handler+Thread也可以执行一个异步的任务,并可以通过handler更新UI。 注:这篇文章只讲API,关于Handler,Looper,Message,MessageQueue的原理我们下一篇讨论。 使用handler+Thread的典型方式是这样的: 必须重写Handler的h

RowandJJ 2791
上一篇: 习惯的力量
下一篇: Android异步2:深入详解 Handler+Looper+MessageQueue
Hel1C
博客等级 码龄17年 6粉丝 106原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值