-
Notifications
You must be signed in to change notification settings - Fork 4
/
ThreadUtils.java
39 lines (34 loc) · 952 Bytes
/
ThreadUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.bytesizebit.androidutils;
import android.os.Looper;
import android.util.Log;
/***********
* Android Utils
* Created by Shahar Barsheshet on 11/06/2015.
* bytesizebit@gmail.com
* www.bytesizebit.com
***********/
public class ThreadUtils {
private ThreadUtils() {
}
/**
* Makes the thread sleep for some time
*
* @param millis time to sleep in millis
*/
public static void threadSleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException ex) {
Log.e("Exception", StringUtils.exceptionStackTraceToString(ex));
}
}
/**
* Check if running on main thread
*/
public static void checkUiThread() {
if (Looper.getMainLooper() != Looper.myLooper()) {
throw new IllegalStateException(
"Must be called from the main thread. Was: " + Thread.currentThread());
}
}
}