是否Thread.sleep()方法,使UI线程睡觉? [英] Does Thread.sleep() makes the UI Thread to sleep?
问题描述
这会不会使当前UI线程睡觉?
尝试
{
视频下载(20);
onProgressUpdate(ⅰ);
}赶上(InterruptedException异常E){
e.printStackTrace();
}
如果你调用睡在UI线程阻塞UI线程。不要叫睡在UI线程上。你不应该阻止用户界面线程。
http://developer.android.com/reference/java/lang/ Thread.html
http://docs.oracle.com/javase/tutorial/至关重要/并发/ sleep.html
您会得到ANR
如果您实施发
或 HandlerThread
,确保在等待工人的UI线程不会阻止线程完成,不叫 Thread.wait()
或视频下载()
。
http://developer.android.com/training/articles/perf- anr.html
另外,请检查下如何避免ANRS的话题
Will this make the current UI thread to sleep?
try
{
Thread.sleep(20);
onProgressUpdate(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
If you are calling sleep on the ui thread it blocks the ui thread. Do not call sleep on the ui thread. You should not block the ui thread.
http://developer.android.com/reference/java/lang/Thread.html
http://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
You will get ANR
If you implement Thread
or HandlerThread
, be sure that your UI thread does not block while waiting for the worker thread to complete—do not call Thread.wait()
or Thread.sleep()
.
http://developer.android.com/training/articles/perf-anr.html
Also check the topic under How to Avoid ANRs
这篇关于是否Thread.sleep()方法,使UI线程睡觉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!