gpt4 book ai didi

android - RxAndroidBle 接收通知更快

转载 作者:行者123 更新时间:2023-11-29 23:51:28 24 4
gpt4 key购买 nike

我是 RxJava 的新手。我现在尝试 RxAndroidBle 并将其与 BLE 的 Android API 实现进行比较。我的外围设备一次发送大量通知(512b block 中大约 30kB)。在 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
);

有没有办法让它更快?

最佳答案

在您的代码 fragment 中,通知在主线程上使用,主线程也用于刷新 UI。如果您不更新 UI 并希望获得尽可能高的性能,您可以删除 .observeOn(AndroidSchedulers.mainThread()) 行。

示例只是示例 — 它们很少针对特定用例(在本例中为性能)进行优化。

牢记your other question并且当 vanilla Android API 和 RxAndroidBle 使用时,操作系统或您的外围设备似乎工作方式不同,这可能也值得问一个问题,即这两种实现是否在相同条件下工作。

关于android - RxAndroidBle 接收通知更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50857496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com