code: int assignDeviceToCursor(final Cursor cursor)
      {
          int currentPriority = cursor.getCurrentDevicePriority();
          IoDevice savedDevice  = cursor.getSavedIoDevice();
  
          /*
           * Give preference to the saved device for this cursor
           */
          if ((savedDevice != null) && (currentPriority < 0))
          {
              int priority = cursor.getDevicePriority(savedDevice);
              cursor.clearSavedIoDevice();
              return attachCursorToDevice(cursor, savedDevice, 1, priority);
          }
          List<IoDevice> availableDevices = getAvailableIoDevices();
          for (IoDevice d : availableDevices)
          {
              IoDevice availableIoDevice = d;
              int priority = cursor.getDevicePriority(availableIoDevice);
  
              Log.d(TAG, "Trying to attach available ioDevice:" + IoDeviceFactory.getXmlString(availableIoDevice) + " to cursor:" + cursor.getId());
          /*
           * If the unused device is compatible with this cursor and
           * has a higher priority than the current device associated
           * with the cursor, use it instead of the current device.
           * If there is no device for this cursor, use the first available.
           */
              if (priority > 0)
              {
                  if (currentPriority < 0)
                  {
                      return attachCursorToDevice(cursor, availableIoDevice, 1, priority);
                  }
                  else if (priority < currentPriority)
                  {
                      return attachCursorToDevice(cursor, availableIoDevice, 0, priority);
                  }
              }
          }
          return -1;
      }
docs: Assign an {@link IoDevice} to the given {@link Cursor}.
  If the cursor is not already attached to an IO device,
  the highest priority device that is compatible with the
  cursor is selected. Otherwise a new device will be assigned
  only if its priority is greater than the one already attached.
  @param cursor
  @return  1 = cursor attached to device and added to scene,
  0 = device replaced on cursor,
  -1 = nothing was done