Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.os.Handler;
import android.os.Looper;

public class Main {
    private static Handler handler;
    private static final byte[] handlerLock = new byte[0];

    public static void post(Runnable run) {
        if (isMainThread()) {
            run.run();
        } else {
            getHandler().post(run);
        }
    }

    public static boolean isMainThread() {
        return Looper.myLooper() == Looper.getMainLooper();
    }

    public static Handler getHandler() {
        synchronized (handlerLock) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper());
            }
        }
        return handler;
    }
}