Skip to main content

Implementing the callback

When you call the startIdentification method, you need to pass an AutomatIdCallback object.

tip

For Android, it is recommended to use the AutomatIdLifecycleCallback subclass, that will ensure that its methods are invoked according to the lifecycle of the provided lifecycleOwner (e.g. fragment), that is, only when your calling activity or fragment is brought back to the started state.

This is necessary, for example, to perform a fragment transaction or a navigation with Jetpack Navigation (androidx.navigation).

AutomatIdManager.startIdentification(requireActivity(), identificationRequest, object : AutomatIdLifecycleCallback(this /* fragment */) {
override fun onSuccess_(result: AutomatIdIdentificationResult.Success) {
findNavController().navigate(HomeFragmentDirections.homeToFeedback(result))
}

override fun onCancel_() {
// no op
}

override fun onError_(error: AutomatIdIdentificationResult.Error) {
// Unrecoverable errors will always abort the identification flow, so we show a feedback screen.
findNavController().navigate(HomeFragmentDirections.homeToFeedback(error))
}

override fun decideRecoverableErrorHandling(error: AutomatIdIdentificationResult.Error): ErrorHandlingDecision {
return ErrorHandlingDecision.RETRY_IDENTIFICATION
}
})