在 AsyncTask 中使用等待
在 AsyncTask
中使用 wait
时,出现 ERROR/AndroidRuntime(24230): Caused by: java.lang.IllegalMonitorStateException: object not lock by thread before wait ()
是否可以使用 Asynctask
只是为了等待?如何?
谢谢
class WaitSplash extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
try {
wait(MIN_SPLASH_DURATION);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute() {
waitSplashFinished = true;
finished();
}
}
When using a wait
in an AsyncTask
, I get ERROR/AndroidRuntime(24230): Caused by: java.lang.IllegalMonitorStateException: object not locked by thread before wait()
Is it possible to use an Asynctask
just for waiting? How?
Thanks
class WaitSplash extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
try {
wait(MIN_SPLASH_DURATION);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute() {
waitSplashFinished = true;
finished();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 Thread.sleep() 而不是
等待()
。Use Thread.sleep() instead of
wait()
.您可以使用 Thread.sleep 方法
You can use Thread.sleep method
如果您只想将方法的执行推迟一段时间,一个不错的选择是 Handler.postDelayed()< /a>
定义处理程序和可运行...
并延迟执行...
If you're looking to just postpone execution of a method for a set amount of time, a good option is Handler.postDelayed()
define the handler and runnable...
and execute with delay...
在触摸事件上使用线程
,线程得到通知..可以根据您的需要进行更改。
Use threads for this
on touch event, thread get notified.. can change according to your need.
您可以通过这种方式使用 asynctask 和 wait();
You have this way to work with asyntask and wait();