原因:com.microlink.RecognizerNotInitializedException:识别器尚未初始化,请确保先调用recognizer.getInstance((.initialize((。
我认为sdk在使用后无法释放相机实例,所以下次回去后再次调用捕获回执时,我会遇到这个问题。
即使活动已关闭,我也可以在logcat中看到此日志重复
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
您可以在您的示例sdk上复制它,也可以只使用自定义识别器视图。
我修复了这个错误,添加了这个:
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');
}
}
}
它在initState 中调用
@override
void initState() {
super.initState();
didChangeAppLifecycleState(AppLifecycleState.detached);
}
文档告诉我们这一点:
处理生命周期状态#从相机插件的0.5.0版本开始,插件不再处理生命周期更改。这意味着当更新生命周期状态。不这样做可能会导致意外行为(例如,如问题#39109中所述(。处理生命周期更改可以通过覆盖didChangeAppLifecycleState方法如下: