Using wait in AsyncTask

jul picture jul · May 25, 2011 · Viewed 88.1k times · Source

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();
    }
}  

Answer

Flo picture Flo · May 25, 2011

Use Thread.sleep() instead of wait().