0

I want to do a simple action in my game after one second. I have my GameScene class which extends Andengine's Scene.

public class GameScene extends Scene{
   //(...)
   Handler delayHandler;

   public GameScene(){
      Looper.prepare();
      delayHandler = new Handler();
   }
   //(...)

   public void sphereTouched(){
      //(...)
      delayHandler.postDelayed(new Runnable() {
         public void run(){
            Log.d("DEB","postDelayed test");
         }
      }, 1000); 
   }
}

When sphereTouched function is called operation from postDelayed doesn't run. Others operations from that function work properly. Have I missed something?

Zuku
  • 1,030
  • 13
  • 21
  • y dont u use Asynctask? – KOTIOS Dec 24 '13 at 18:48
  • did you initialize delayHandler? – Matt Dec 24 '13 at 18:49
  • I don't know if this is related (perhaps you have two separate handlers and only initializing one?) or not (maybe just a mistake in the code posted here), but note that you're using `delayHandler` in `sphereTouched` but only initializing `handler` in the constructor. – kabuko Dec 24 '13 at 19:11
  • anything in the log ? – njzk2 Dec 24 '13 at 19:15
  • @kabuko - sorry, i made a mistake when was writing a question. There's a delayHandler in constructor (I just corrected it). – Zuku Dec 24 '13 at 19:24
  • @njzk2 - there's no messages related to handler in LogCat – Zuku Dec 24 '13 at 20:57
  • is it possible that you are never releasing the thread you are working on (is sphereTouched method called from a loop in a run method, for example?) – njzk2 Dec 25 '13 at 23:27

1 Answers1

0

use this code for handler.

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            // your code
        }
    }, 1000);
Golil
  • 467
  • 4
  • 12