线程切换工具类
1. 源码
import android.os.Handler;
import android.os.Looper;
/**
* 线程切换工具
*/
public class BigUtilsThread {
private static Handler mHandler = new Handler(Looper.getMainLooper());
// 在主线程中运行
public static void runOnUiThread(Runnable r) {
if (Looper.myLooper() == Looper.getMainLooper()) {
//主线程
r.run();
} else {
//子线程
mHandler.post(r);
}
}
// 在子线程中运行
public static void runOnSubThread(Runnable r) {
new Thread(r).start();
}
}