Thread.sleep()是否使UI线程进入hibernate状态?

这会使当前的UI线程进入睡眠状态吗?

try { Thread.sleep(20); onProgressUpdate(i); } catch (InterruptedException e) { e.printStackTrace(); } 

如果你在ui线程上调用sleep,它会阻塞ui线程。 不要在ui线程上调用sleep。 你不应该阻止ui线程。

http://developer.android.com/reference/java/lang/Thread.html

http://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html

你会得到ANR

如果您实现ThreadHandlerThread ,请确保您的UI线程在等待工作线程完成时不会阻塞 – 不要调用Thread.wait()Thread.sleep()

http://developer.android.com/training/articles/perf-anr.html

另请查看如何避免ANR的主题

仅在从UI线程调用时

Thread.sleep(time)将导致发送此消息的线程在给定的时间间隔内hibernate。 因此,如果您在UI线程中调用它,它将影响UI线程。 就android而言,不建议以任何方式阻碍UI线程,否则会导致ANR – 应用程序无响应。

你可以参考这个

好吧,语言中的任何静态方法都可以在对象引用而不是类上调用。 但这并没有改变function:Thread.sleep()是一个静态方法,它将当前线程置于hibernate状态。