我是RxJava的新手。我现在尝试使用RxAndroidBle,并将其与Android API for BLE实现进行比较。我的外围设备一次发送大量notifications (大约30kB / 512b块)。在Rx中,大约需要10-12秒才能全部接收到它们。当我尝试使用Android API时,大约需要2-3秒。
在我的RxAndroidBle实现中,我按照示例应用程序中的建议进行操作:
connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(UUID.fromString(mCharacteristicUUID)))
.doOnNext(notificationObservable -> runOnUiThread(this::notificationHasBeenSetUp))
.flatMap(notificationObservable -> notificationObservable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
this::onNotificationReceived,
this::onNotificationSetupFailure
);有没有办法让它更快?
发布于 2018-06-16 03:01:11
在您的代码片段中,通知在主线程上使用,该线程也用于刷新UI。如果你没有更新UI,并且想要达到最高的性能,你可以去掉.observeOn(AndroidSchedulers.mainThread())行。
样本只是样本-它们很少针对特定的用例进行优化(在这种情况下是性能)。
考虑到your other question和OS或您的外围设备在使用普通的Android API和RxAndroidBle时似乎工作方式不同,可能还值得问一个问题,这两种实现是否在相同的条件下工作。
https://stackoverflow.com/questions/50857496
复制相似问题