Hi everyone,
In our application we need to implement polling and from the samples we were provided the closest one is the UMGDemo. Based on it we have the following code:
public boolean nUIEventCallback(nUIObject object, int evt_type) {
switch (object.nuiid) {
case NUIID_ENVIRONMENTS_STATE_TIMER: {
if (evt_type == EVT_TIMER_COMPLETE) {
System.out.println("Tick!");
object.tick();
createComponent();
//addTimerObject();
}
break;
}
}
return true;
}
private void addTimerObject () {
nUITimerObject timer = new nUITimerObject (NUIID_ENVIRONMENTS_STATE_TIMER, 1000);
timer.addEventListener(this, true);
view.add(timer);
}
public nUIViewDisplay createComponent() {
view = new nUIViewDisplay(-1);
addTimerObject();
return view;
}
My questions are:
- what is the purpose of the tick method? And is it important to call it everytime?
- Should we recreate the whole view on every TIMER event or it’s OK just to add the nUITimerObject? I guess that the second approach is not prefferable because no one removes the old timers.
- is there an object that fires event on a fixed amount of time (something like TimerTask?)
- if we implement this functionality just starting a new thread and using a flag, is it enough for this flag to be volatile (how will this be cross-compiled?) and we should implement monitor pattern or something like that (again how will this be cross-compiled?) ?
Thanks,
Nenko