services-api / com.keecker.services.interfaces / KeeckerServiceConnection
KeeckerServiceConnection
class KeeckerServiceConnection<ServiceInterface :
IInterface
> :
PersistentServiceConnection
<
ServiceInterface
>
A PersistentServiceConnection wrapping AIDL calls to handle potential IPC errors automatically.
Parameters
context
- Android context used to bind and rebind. It must be valid during the whole
bind duration. In most of the cases you should give the Application Context.
bindingInfo
- Information needed to bind to the service and use its AIDL interface.
exceptionListener
- Notifies about internal exceptions, swallowed when retrying the call.
bindingTimeoutMs
- Kills the current EphemeralServiceConnection if it did not try to
reconnect during this period of time (milliseconds). When a service
crashes multiple times, Android may wait a bit before attempting to
rebind. This can be more than 10 seconds.
Parameters
Constructors
<init> | KeeckerServiceConnection(context: Context , bindingInfo: ServiceBindingInfo < ServiceInterface >, exceptionListener: RemoteExceptionListener ? = null, bindingTimeoutMs: Long = 60000) A PersistentServiceConnection wrapping AIDL calls to handle potential IPC errors automatically. |
Properties
bindingInfo | val bindingInfo: ServiceBindingInfo < ServiceInterface > Information needed to bind to the service and use its AIDL interface. |
bindingTimeoutMs | val bindingTimeoutMs: Long Kills the current EphemeralServiceConnection if it did not try to reconnect during this period of time (milliseconds). When a service crashes multiple times, Android may wait a bit before attempting to rebind. This can be more than 10 seconds. |
context | val context: Context Android context used to bind and rebind. It must be valid during the whole bind duration. In most of the cases you should give the Application Context. |
exceptionListener | val exceptionListener: RemoteExceptionListener ? Notifies about internal exceptions, swallowed when retrying the call. |
Functions
| execute | suspend fun <T> execute(lambda: (
ServiceInterface
) ->
T
):
T
?
- Wraps an AIDL call and retries it once if it failed.
- Lazily binds before executing the AIDL call.
| | onNewServiceInstance |fun onNewServiceInstance(lambda: suspend (
ServiceInterface
) ->
Unit
):
Unit
- Notifies when binding to a new Service instance. May it be because it is the first time we connect to it, or because it crashed.
- Does not notify when unbinding then rebinding to the same Service instance
- Called before exectuting any AIDL call that is triggered the bind
- Typically used to get the service to its expected state, like resubscribing to some data after a crash.
| | unbind |fun unbind():
Unit
Unbind to the service. |