The recognizer has not been initialized, make sure to call Recognizer.getInstance().initialize() first

1.4k Views Asked by At

Caused by: com.microblink.RecognizerNotInitializedException: The recognizer has not been initialized, make sure to call Recognizer.getInstance().initialize() first.

I think the sdk is not able to release camera instance after use, so next time when capture receipt is invoked again after going back I am getting this issue.

I can see this log repeating in logcat even when the activity is closed

I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.samsung.adaptivebrightnessgo API Level 2
I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.samsung.adaptivebrightnessgo API Level 2
I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.samsung.adaptivebrightnessgo API Level 2
I/CameraManagerGlobal: Camera 1 facing CAMERA_FACING_FRONT state now  CAMERA_STATE_CLOSED for client com.samsung.adaptivebrightnessgo API Level 2

You can reproduce it on your sample sdk as well just use the custom recognizer view.

1

There are 1 best solutions below

0
Alejandro Farel On

I fix this error add this:

  void didChangeAppLifecycleState(AppLifecycleState state) {
    // App state changed before we got the chance to initialize.
    if (_controller == null || !_controller!.value.isInitialized) {
      return;
    }
    if (state == AppLifecycleState.inactive) {
      _controller?.dispose();
    } else if (state == AppLifecycleState.resumed) {
      if (_controller != null) {
        print('muere');
      }
    }
  }

its called in initState

  @override
  void initState() {
    super.initState();
    didChangeAppLifecycleState(AppLifecycleState.detached);
  }

The documentation tells us about this:

Handling Lifecycle states # As of version 0.5.0 of the camera plugin, lifecycle changes are no longer handled by the plugin. This means developers are now responsible to control camera resources when the lifecycle state is updated. Failure to do so might lead to unexpected behavior (for example as described in issue #39109). Handling lifecycle changes can be done by overriding the didChangeAppLifecycleState method like so: