private Handler mHandler = new Handler(getContext().getMainLooper());
public void runOnUiThread(Context mContext,Runnable action){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
if (Thread.currentThread() != mContext.getMainLooper().getThread()) {
mHandler.post(action);//将Runnable Post到消息队列,由内部的mHandler来处理,实际上也是Handler的处理方式
} else {
action.run();//已经在UI线程,直接运行。
}
}
}
网友评论