diff options
Diffstat (limited to 'main/java/com/google/android/setupcompat/internal/Preconditions.java')
-rw-r--r-- | main/java/com/google/android/setupcompat/internal/Preconditions.java | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/main/java/com/google/android/setupcompat/internal/Preconditions.java b/main/java/com/google/android/setupcompat/internal/Preconditions.java index 259377c..1346c24 100644 --- a/main/java/com/google/android/setupcompat/internal/Preconditions.java +++ b/main/java/com/google/android/setupcompat/internal/Preconditions.java @@ -61,4 +61,14 @@ public final class Preconditions { } throw new IllegalStateException(whichMethod + " must be called from the UI thread."); } + /** + * Ensure that this method is not called from the main thread, otherwise an exception will be + * thrown. + */ + public static void ensureNotOnMainThread(String whichMethod) { + if (Looper.myLooper() != Looper.getMainLooper()) { + return; + } + throw new IllegalThreadStateException(whichMethod + " cannot be called from the UI thread."); + } } |