Skip to content

Instantly share code, notes, and snippets.

@pyricau
Created November 29, 2012 09:59
Show Gist options
  • Save pyricau/4167919 to your computer and use it in GitHub Desktop.
Save pyricau/4167919 to your computer and use it in GitHub Desktop.
Check that your UI APIs are called from the UI Thread
public class ThreadPreconditions {
public static void checkOnMainThread() {
if (BuildConfig.DEBUG) {
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException("This method should be called from the Main Thread");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment