How to know if this thread is a UI Thread

前端 未结 4 959
走了就别回头了
走了就别回头了 2021-02-05 06:28

Is there any way on Android to know, if the thread running my code, is the UI Thread or not ? In swing there was SwingUtilities.isEventDispatchThread() to tell me

4条回答
  •  迷失自我
    2021-02-05 06:50

    Put a breakpoint where you want to check and, when it gets hit, check if you can interact with your UI (ie, if the UI is not frozen). If you can't interact with the UI then you are in the UI Thread, otherwise you are in a background thread.

提交回复
热议问题