Updating GUI: Runnables vs Messages

前端 未结 4 1688
再見小時候
再見小時候 2020-12-23 13:52

To update the GUI from other threads, there are basically two main approaches:

  1. Use java.lang.Runnable with any of these methods:

    Activity.r         
    
    
            
4条回答
  •  渐次进展
    2020-12-23 14:10

    Handler interface provides much more functionality than runOnUiThread(), according to docs:

    There are two main uses for a 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.

    runOnUiThread does only a subset of (2). ie "enqueue an action to be performed on UI thread"

    So IMO unless you need those extra features runOnUiThread is sufficient and preferred way.

提交回复
热议问题