Example usage for android.os Looper getThread

List of usage examples for android.os Looper getThread

Introduction

In this page you can find the example usage for android.os Looper getThread.

Prototype

public @NonNull Thread getThread() 

Source Link

Document

Gets the Thread associated with this Looper.

Usage

From source file:Main.java

public static Handler runInUIThread(final Runnable runnable, boolean runImmediatelyIfPossible) {
    if (runnable == null) {
        return null;
    }//from   w  w  w .  j  a  v  a 2  s.c o  m

    final Handler handler;
    Looper mainLooper = Looper.getMainLooper();
    if (runImmediatelyIfPossible && (Thread.currentThread() == mainLooper.getThread())) {
        handler = null;
        runnable.run();
    } else {
        handler = new Handler(mainLooper);
        handler.post(runnable);
    }

    return handler;
}