Java tutorial
//package com.java2s; import android.os.Looper; public class Main { public static void checkMainThread() { boolean error = false; if (Looper.myLooper() == null || Looper.getMainLooper() != Looper.myLooper()) { error = true; } if (error == true) { throw new RuntimeException("Must be in UI thread!"); } } }