Removing Routes


My app does the following (in order)
  1. do a single read of battery level
  2. when user triggers a recording state, perform a streaming read of battery level
To perform the single read, I create a route, then trigger a single read.  After the route receives data, I call route.remove().

To perform the streaming read, I create a route, then use a timer to trigger periodic reads.

The issue is that the route from the single read is receiving data from the periodic reads, even after route.remove() was called successfully.  Is there another call I should be making instead of or in addition to route.remove()?  I can call board.tearDown but this removes all routes instead of selective routes.

The code for the single read is:
Settings settings = board.getModule(Settings.class)
MutableObject batteryRoute = new MutableObject<>();
settings.battery().addRouteAsync((source) -> {, env) -> {
if (batteryRoute.getValue() == null) {
Log.i("debug", "Stale read ...");

Settings.BatteryState batteryState = data.value(Settings.BatteryState.class);

// logic to display current battery state

// Remove the route

// Remove reference to the route
}).continueWith((task) -> {
return null;


  • Hrm, I'll have to look into this issue.  Off hand, removing the route should clear the subscribers as well so it's odd that you are still receiving data on your old route.

    For now, you can use a boolean flag to only execute a piece of code one time.
This discussion has been closed.