From 23105feae67cf7cb9ceef55b3dfd0c84494f1ce7 Mon Sep 17 00:00:00 2001 From: Blankj <625783482@qq.com> Date: Fri, 18 May 2018 19:24:01 +0800 Subject: [PATCH] see 05/18 log --- .../com/blankj/utilcode/util/ThreadUtils.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 utilcode/src/main/java/com/blankj/utilcode/util/ThreadUtils.java 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 00000000..ef9759be --- /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(); + } + + +} -- GitLab