Removing existing timers

edited August 2016 in Android
I'm currently working on an App which communicates with a MetaWear RG.
The main theory is that the board schedules a timer which logs temperature data. Whenever a device with the app open is near, it will consume the log.

However, upon creating the very first connection I have to create a route for logging and schedule a timer, but it is not certain whether timer has already been scheduled earlier. Result; multiple timers write to the log which causes my log to bloat. 

Is it possible to remove the timers which are currently on the board? 

The following piece of code is not doing it for me;
 	Timer timerModule = mwBoard.getModule(Timer.class);
timerModule.removeTimers();
mwBoard.setConnectionStateHandler(new MetaWearBoard.ConnectionStateHandler() {
@Override
public void connected() {
try {
Timer timerModule = mwBoard.getModule(Timer.class);
AsyncOperation<Timer.Controller> taskResult = timerModule
.scheduleTask(new Timer.Task() {
@Override
public void commands() {
tempModule.readTemperature(tempModule.getSources().get(MultiChannelTemperature.MetaWearRChannel.NRF_DIE));
}
}, TIME_DELAY_PERIOD, false);
taskResult.onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
result.start();
}

@Override
public void failure(Throwable error) {
super.failure(error);
}
});
} catch (UnsupportedModuleException e) {
}
}

@Override
public void failure(int status, final Throwable error) {
}

@Override
public void disconnected() { mwBoard.connect();
}
});
mwBoard.disconnect();

Comments

  • The removeTimers function only removes timers it is aware of.  If your are running the code from a clean app state, you will either need to serialize and restore the previous API state to use removeTimers or reset the board.
This discussion has been closed.