gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:38:22 27 4
gpt4 key购买 nike

有没有区别

new Handler.post(Runnable r);

activity.runOnUiThread(Runnable r)

最佳答案

来自官方Handler文档

处理程序

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

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

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

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

runOnUiThread

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com