In version 3, all reconnection logic is now handled via the ReconnectFilter interface. There are a few default implementations already provided, and most of the time you shouldn't have to adjust these.
When dealing with reconnections, it's important to note the distinction between the two methods in the ReconnectFilter interface.
onConnectFailed(ConnectFailEvent) - This method is called when the library fails to establish a connection to a BleDevice when it was not connected prior.
onConnectionLost(ConnectionLostEvent) - The method is called by the library when we previously had a connection to the device (it was in the
CONNECTED state), but have since lost that connection. This method is related to the states RECONNECTING_SHORT_TERM and RECONNECTING_LONG_TERM
Default implementation of DeviceReconnectFilter (which extends
ReconnectFilter). This class has a few constructors which allow you to change the default settings for the filter (how many attempts to retry a connection, how long the library should try to establish a reconnection, etc.). The defaults are:
- Retry failed connection attempts twice (for a total of 3 connection attempts)
- Retry connecting lost connections
- Short term reconnect runs a total of 5 seconds, with 1 second between each retry
- Long term reconnect runs a total of 5 minutes, with 5 seconds of delay between each retry