Java tutorial
//package com.java2s; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.view.WindowManager; public class Main { public static ProgressDialog createProgressDialog(Context mContext) { final ProgressDialog dialog = new ProgressDialog(mContext); try { Activity a = (Activity) mContext; a.runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); } catch (WindowManager.BadTokenException e) { } dialog.setCancelable(false); return dialog; } }