android - Handler.post(Runnable r) 和 Activity.runOnUiThread(Runnable r) 的区别

标签 android handler ui-thread

有没有区别

new Handler.post(Runnable r);

activity.runOnUiThread(Runnable r)

最佳答案

来自官方Handler文档

处理程序

处理程序有两个主要用途:

(1) To schedule messages and runnables to be executed as some point in the future.

(2) To enqueue an action to be performed on a different thread than your own.

简而言之,Handler就是用来管理不同的Runnables的。

runOnUiThread

It is used to execute the non-UI operation on the UI Thread, example if you want to update the screen from AsyncTask's doInBackground() you have to write the part of code that update's the UI inside the runOnUiThread(). But again that will block the UI.

关于android - Handler.post(Runnable r) 和 Activity.runOnUiThread(Runnable r) 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7452884/

相关文章:

java - 更改线程中 View 的大小,而不是 UI 线程

java - 每秒从另一个线程更新 swt ui

android - 懒加载ListView(不是那种懒)

Android M - 自定义权限对话框样式

matlab - 在 Matlab 中使用函数句柄

javascript - 仅在子菜单存在时显示图标

c - 使用报警功能

android - Android 处理程序的使用

android - 如何在android中清空 Volley 请求队列

java - 如何将麦克风音频流式传输到同一设备 throw 扬声器