set Observer
Registers an observer to monitor the service connection state.
Allows integrators to react to changes in the service readiness state (connected or disconnected) in a lifecycle-aware manner. The observer will be notified whenever the service connection state changes.
Example:
serviceUtil.setObserver(this, isReady -> {
if (isReady) {
textView.setText(serviceUtil.getSerialNumber());
} else {
textView.setText("Service not ready");
}
});
Content copied to clipboard
Parameters
owner
The LifecycleOwner (e.g., Activity or Fragment) that controls the observer's lifecycle. The observer will automatically stop receiving updates when the owner is destroyed.
observer
The Observer to receive updates when the service connection state changes. The Boolean value indicates if the service is ready (true) or not (false).