Andengine - handler.postDelayed doesn't work

688 Views Asked by At

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?

1

There are 1 best solutions below

5
On

use this code for handler.

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

        @Override
        public void run() {
            // your code
        }
    }, 1000);