Java tutorial
//package com.java2s; /** * Appcelerator Titanium Mobile * Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the Apache Public License * Please see the LICENSE included with this distribution for details. */ import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; public class Main { /** * Run the Runnable "delayed" by using an AsyncTask to first require a new * thread and only then, in onPostExecute, run the Runnable on the UI thread. * @param runnable Runnable to run on UI thread. */ public static void runUiDelayed(final Runnable runnable) { (new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... arg0) { return null; } /** * Always invoked on UI thread. */ @Override protected void onPostExecute(Void result) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(runnable); } }).execute(); } }