HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to check if current thread is not main thread

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howcheckcurrentmainnotthread

Problem

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?

Solution

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


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

Code Snippets

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

Context

Stack Overflow Q#11411022, score: 826

Revisions (0)

No revisions yet.