这会让当前的UI线程休眠吗?
try
{
Thread.sleep(20);
onProgressUpdate(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
这会让当前的UI线程休眠吗?
try
{
Thread.sleep(20);
onProgressUpdate(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
只有当从UI线程调用时才会执行。
http://developer.android.com/reference/java/lang/Thread.html
http://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
你会得到ANRhttp://developer.android.com/training/articles/perf-anr.html
也要查看“如何避免ANR”主题下的内容。Thread.sleep(time)
会导致发送该消息的线程在给定的时间间隔内睡眠。因此,如果您在UI线程中调用它,它将影响UI线程。就安卓而言,不建议以任何方式阻塞UI线程,否则会导致ANR-应用程序无响应。
您可以参考this