0

I use the NSTimer in robovm , but it not work, I don't know why? here is my code:

mTimer = NSTimer.create(1, new VoidBlock1<NSTimer>() {                  
                    @Override
                    public void invoke(NSTimer a) {
                            onUpdate();
                           System.out.println("onUpdate");
                    }

            }, true);

But not happen.

other way:

mTimer = NSTimer.create(1, this, Selector.register("onUpdate"), null, true);

@Method(selector = "onUpdate")
    public void onUpdate(){
    System.out.println("onUpdate");
}

nothing happen too. and other way is also not work

mTimer = NSTimer.create(1, this, Selector.register("onUpdate:"), null, true);

@Callback @BindSelector("onUpdate:")
public void onUpdate(Selector cmd){
    System.out.println("onUpdate");
}

it also not work . please help me .

badboy_tqj
  • 300
  • 2
  • 14

1 Answers1

0

I have not tested this, but looking at the NSTimer.java it seems that you might be creating a timer without starting/firing it.

Perhaps you can try method createScheduled():

mTimer = NSTimer.createScheduled(1, new VoidBlock1<NSTimer>() {                  
                @Override
                public void invoke(NSTimer a) {
                        onUpdate();
                       System.out.println("onUpdate");
                }

        }, true);

Alternatively if you don't really need it to be an NSTimer I'd recommend using the java.util.Timer. Which works great on Robovm applications.

p.streef
  • 3,652
  • 3
  • 26
  • 50