如何检查当前线程是否不是主线程 [英] How to check if current thread is not main thread

查看:55
本文介绍了如何检查当前线程是否不是主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查运行某段代码的线程是否是主(UI)线程.我怎样才能做到这一点?

I need to check if the thread running a certain piece of code is the main (UI) thread or not. How can I achieve this?

推荐答案

Looper.myLooper() == Looper.getMainLooper()

如果返回 true,那么您就在 UI 线程上!

if this returns true, then you're on the UI thread!

这篇关于如何检查当前线程是否不是主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆