Android 2.2的:你怎么能写一个辅助方法让自己的应用“睡眠”n毫秒? [英] Android 2.2: How can you write a helper method to have your app 'sleep' for N milliseconds?
本文介绍了Android 2.2的:你怎么能写一个辅助方法让自己的应用“睡眠”n毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要写,我可以在不同的地方使用的应用程序从根本上使睡眠一个辅助方法对于N milliseconds.It看起来Handler.postAtTime可能是做这件事,但我想任何code片段(如果可用)。
I need to write a helper method which I can use in various places in the app to essentially make it 'sleep' for N milliseconds.It looks like Handler.postAtTime may be one way to do it, but I'd like any code snippets if available.
推荐答案
您是否正在寻找这样的事情?
Are you looking for something like this?
try {
//Put the thread to sleep for the desired amount of time (milliseconds)
Thread.currentThread().sleep(1000);
}
catch(InterruptedException ie){
}
这将让你从睡眠调用它为您指定的时间量线程。
This will put the thread you are calling it from to sleep for the amount of time you specify.
这篇关于Android 2.2的:你怎么能写一个辅助方法让自己的应用“睡眠”n毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文