如何知道正在运行的代码是否在主线程(UI线程)上执行?
对于 Swing,我使用 isEventDispatchThread
方法...
最佳答案
使用 Looper.getMainLooper().getThread() 来获取 UI 线程。您可以使用以下表达式检查它是否是当前线程:
Looper.getMainLooper().getThread() == Thread.currentThread()
关于android - 如何检查是否在 Android 的 UI 线程上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1845678/