aws / amazon-freertos-ble-android-sdk

Android SDK for FreeRTOS Bluetooth Devices.
Apache License 2.0
49 stars 41 forks source link

Fix disconnect behavior in app DeviceScanFragment #36

Closed ravibhagavandas closed 3 years ago

ravibhagavandas commented 3 years ago

Issue #, if available: For user initiated disconnects, the app clears the UI buttons by calling resetUI() which in turn calls onCheckedChanged() listener. The code prevents disconnecting twice by checking for aDevice != NULL. However the callback could be triggered before setting aDevice to NULL and cause a double disconnect.

Description of changes: Set the callback listener to null so that onCheckedChanged() will not be invoked for resetting the UI. Set the device to null before disconnect to prevent double disconnect. Refactor some functions for better readability.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

dachalco commented 3 years ago

Thanks for the readability improvements. These were much needed.