Monday, 13 February 2017

java - How to check if current thread is not main thread



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?


Answer



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



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


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...