Timer is still firing after Clicking on other Links in GWT -


so have timer , keeps on firing though cleared panel , loaded other model... question is, how cancel timer when unload model?

so here part of code

public display(list<clarification> result) {      if (result.size() == 0) {         window.alert("empty");     } else {           rootpanel.get("dev1").clear();          t = new timer() {             public void run() {                  cd = new clarificationdispatcher();                 cd.getclarificationscount(result.size());             }         };         t.schedulerepeating(5000); 

}

i tried cancel timer onunload() method however, don't believe getting called @ all...

thanks!

steps follow

  • use window.onunload event called when page refreshed
  • first export canceltimer() method java script using jsni , register canceltimerfunction java script function called on page unload
  • cancel timer on window close

code:

import com.google.gwt.user.client.timer; import com.google.gwt.user.client.window;  private static timer timer = null;  public void onmoduleload() {     exportcanceltimer();      final label label = new label("hello ");     timer = new timer() {          @override         public void run() {             label.settext("hello " + math.random() * 100);         }      };      timer.schedulerepeating(500);     rootpanel.get().add(label);      window.addclosehandler(new closehandler<window>() {          @override         public void onclose(closeevent<window> event) {             timer.cancel();         }     });  }   public static void canceltimer() {     if (timer != null) {         system.out.println("cancel");         timer.cancel();     } }  public static native void exportcanceltimer() /*-{     $wnd.canceltimerfunction = $entry(@com.x.y.z.gwtproject::canceltimer());     $wnd.onunload = $wnd.canceltimerfunction; }-*/; 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -