Brijesh Masrani
Brijesh Masrani

Reputation: 1449

how to put a thread in Wait in Android

I have a thread running in my program When Mouse-down Event generates I want to put that thread in wait() and in Mouse-up I want to Notify that thread

But when I tried to do this It is giving me error like "Object not locked by Thread" so can anyone help me how to solve this..

Upvotes: 1

Views: 10779

Answers (3)

Brad Hein
Brad Hein

Reputation: 11057

Just use Thread.sleep() and then Thread.interrupt() to wake it up.

something like this:

Thread t;

startThread() {
  t = new Thread() {
    public void run () {
       doThings();
       sleep(10000);
    }
  }

  t.start();
}

interruptThread() {
  if (t != null) t.interrupt();
}

Upvotes: 3

xamar
xamar

Reputation: 269

You can't stop the UI Thread (this is the Thread that called the event). This Thread is used to dispatch UI events and if you could make it wait() it'll render your UI unresponsive.

You'll have to create your own Thread.

Upvotes: 2

mtmurdock
mtmurdock

Reputation: 13062

as far as i know, calling wait() on a thread causes a crash... i dont know if there is a safe way to pause a thread (or at least an easy way)

Upvotes: 0

Related Questions