首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Handler 是主线程与子线程沟通的桥梁

Handler 是主线程与子线程沟通的桥梁

原创
作者头像
用户10171634
发布2025-08-18 11:14:24
发布2025-08-18 11:14:24
1190
举报

* <p>When a

* process is created for your application, its main thread is dedicated to

* running a message queue that takes care of managing the top-level

* application objects (activities, broadcast receivers, etc) and any windows

* they create. You can create your own threads, and communicate back with

* the main application thread through a Handler. This is done by calling

* the same <em>post</em> or <em>sendMessage</em> methods as before, but from

* your new thread. The given Runnable or Message will then be scheduled

* in the Handler's message queue and processed when appropriate.

即使你在后台线程中调用 handler.post(),任务也还是会被送到 Handler 所绑定的线程(通常是主线程)中执行。

Handler 是主线程与子线程沟通的桥梁

这样避免了多线程通信的麻烦

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档