2015-05-11 47 views
0

我在robovm中使用NSTimer,但它不工作,我不知道爲什麼? 這裏是我的代碼:Ho在robovm中使用NSTimer?

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

      }, true); 

但沒有發生。

其他方式:

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

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

沒有發生過。等方式也行不通

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

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

它也行不通。請幫幫我 。

回答

0

我還沒有測試過這個,但看着NSTimer.java看起來你可能正在創建一個定時器而沒有啓動/啓動它。

或許你可以嘗試的方法createScheduled():

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

     }, true); 

另外,如果你不真正需要的是一個NSTimer我建議使用java.util.Timer中。這對Robovm應用程序很有用。