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 {
    public static Handler mMainHandler;

    public static void runInMainThread(Runnable runnable) {
        if (isInMainThread()) {
            runnable.run();
        } else {
            post(runnable);
        }
    }

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

    public static boolean post(Runnable runnable) {
        return getMainThreadHandler().post(runnable);
    }

    public static Handler getMainThreadHandler() {
        if (mMainHandler == null) {
            mMainHandler = new Handler(Looper.getMainLooper());
        }
        return mMainHandler;
    }
}