安卓:什么是Activity.runOnUiThread和View.post之间的区别? [英] Android: What's the difference between Activity.runOnUiThread and View.post?
问题描述
什么的区别 Activity.runOnUiThread
和 View.post
,可能有人,请解释一下?
What's the difference between Activity.runOnUiThread
and View.post
, could someone, please, explain?
推荐答案
有没有真正的区别,不同之处在于 View.post
是有用的,当你没有直接访问活动。
There is no real difference, except that the View.post
is helpful when you don't have a direct access to the activity.
在这两种情况下,如果没有对UI线程,<一href="http://developer.android.com/reference/android/os/Handler.html#post%28java.lang.Runnable%29"><$c$c>Handler#post(Runnable)$c$c>将被称为幕后。
In both cases, if not on UI thread, Handler#post(Runnable)
will be called behind the scenes.
由于CommonsWare在注释中提到的,这两者之间的差异 - 对UI线程调用时,活动#runOnUiThread
将调用运行
方法直接,而查看#交
将发布可运行
队列(如呼叫在处理程序#交
)
As CommonsWare mentioned in the comment, there is a difference between the two - when called on Ui thread, Activity#runOnUiThread
will call the run
method directly, while View#post
will post the runnable
on the queue (e.g. call the Handler#post
)
最重要的一点IMO是,都具有相同的目标,而对于谁使用它,不应该有差别(和实现可能在未来改变)。
The important point IMO is that both have the same goal, and for whoever use it, there should be no difference (and the implementation may change in the future).
这篇关于安卓:什么是Activity.runOnUiThread和View.post之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!