Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.os.Handler;
import android.os.Looper;

public class Main {
    private static Handler sMainThreadHandler;

    /**
     * Queues a task in the main thread to be executed after a certain delay.<br>
     * 
     * @param toExecute
     *            - task to execute.
     */
    public static final void queueOnMain(final Runnable toExecute, final long delayMillis) {
        getMainThreadHandler().postDelayed(toExecute, delayMillis);
    }

    /**
     * @return handler associated with the main (UI) thread.
     */
    public static final Handler getMainThreadHandler() {
        if (sMainThreadHandler == null) {
            sMainThreadHandler = new Handler(Looper.getMainLooper());
        }
        return sMainThreadHandler;
    }
}