RxAndroidBle可以更快地接收通知

问题描述 投票:0回答:1

我在RxJava很新。我现在尝试使用RxAndroidBle并将其与BLE的Android API实现进行比较。我的外围设备一次发送了很多notifications(512b块大约30kB)。在Rx中,接收它们大约需要10-12秒。当我尝试使用Android API时,大约需要2-3秒。

在我的RxAndroidBle实现中,我按照示例app中的建议执行:

connectionObservable
    .flatMap(rxBleConnection -> rxBleConnection.setupNotification(UUID.fromString(mCharacteristicUUID)))
    .doOnNext(notificationObservable -> runOnUiThread(this::notificationHasBeenSetUp))
    .flatMap(notificationObservable -> notificationObservable)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(
        this::onNotificationReceived,
        this::onNotificationSetupFailure
    );

有没有办法让它更快?

android bluetooth-lowenergy rxandroidble
1个回答
0
投票

在您的代码剪切中,通知将在主线程上使用,主线程也用于刷新UI。如果您没有更新UI并希望获得最高性能,您可以摆脱.observeOn(AndroidSchedulers.mainThread())线。

样本只是样本 - 它们很少针对特定用例(在这种情况下的性能)进行优化。

考虑到your other question以及操作系统或您的外围设备在使用vanilla Android API和RxAndroidBle时的工作方式似乎不同,也可能值得问一个问题是两个实现是否在相同的条件下工作。

© www.soinside.com 2019 - 2024. All rights reserved.