diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/ThreadUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/ThreadUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..ef9759be300dc8438fecc2d39863f27ddb4623dd --- /dev/null +++ b/utilcode/src/main/java/com/blankj/utilcode/util/ThreadUtils.java @@ -0,0 +1,30 @@ +package com.blankj.utilcode.util; + +import android.os.Looper; + +/** + *
+ * author: Blankj + * blog : http://blankj.com + * time : 2018/05/17 + * desc : + *+ */ +public class ThreadUtils { + + /** + * Returns {@code true} if called on the main thread, {@code false} otherwise. + */ + public static boolean isOnMainThread() { + return Looper.myLooper() == Looper.getMainLooper(); + } + + /** + * Returns {@code true} if called on a background thread, {@code false} otherwise. + */ + public static boolean isOnBackgroundThread() { + return !isOnMainThread(); + } + + +}