处理器VS主题 [英] Handler vs Thread

查看:111
本文介绍了处理器VS主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,一劳永逸。我读过很多地方。当我想要做一些很长一段时间的操作,我应该使用处理程序

I would like to know, once for all. I've read in many places. When I want do some 'long time operations' I should use a Handler.

但我不知道为什么?我所有的长时操作我周围有一个普通的线程,并能正常工作。

But I don't get why? All my 'long-time-operations' I surround with a regular threads, and it works fine.

我为什么要使用处理程序此?

唯一一次我不得不用<$​​ C $ C>处理程序是,当我不得不安排一些任务( postDelayed

The only time I had to use Handler was, when I had to schedule some task(postDelayed)

有什么主要的想法我想念处理(当我真的应该使用它)?或者,也许确实没有区别?

Is there any main idea I miss about handlers(When I should really use it)? Or maybe there isn't really difference?

推荐答案

一个处理器让你从你的后台线程UI线程进行通信了。这是因为,UI操作是由后台线程内禁止的。需要注意的是,在开始的1.5版,该 AsyncTask的类使得它更容易做到这一点。

A Handler lets you communicate back with the UI thread from your background thread. This is because UI operations are forbidden from within background threads. Note that starting at version 1.5, the AsyncTask class makes it much easier to do so.

这篇关于处理器VS主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆