I have this code block:
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
final CameraController? cameraController = _controller;
// App state changed before we got the chance to initialize.
if (cameraController == null || !cameraController.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
cameraController.dispose();
} else if (state == AppLifecycleState.resumed) {
_initializeCamera();
}
}
It is similar to the code block provided in the Camera Plugin documentation(https://pub.dev/documentation/camera/latest/) except I handled the camera list inside the _initializeCamera() instead of passing it in as an argument.
The issue I am having is when I was debugging my code, I noticed that this function will keep getting called when I am switching between apps on the phone. During the first time it’s called it will dispose the controller as expected, but then it will continue calling itself until binding.dart calls didHaveMemoryPressure() and stops it from calling itself. When I switch back to the app it does fire off the _initializeCamera() and everything works normal. If I didn’t put a breakpoint there it would run as if there was no problem.
I guess it works as in it does dispose the controller and reinitialize it like nothing happened, but it doesn’t seem normal. Can anyone tell me what’s going on here.
Tried setting controller to null with the dispose, and also tried using cameraController.start and .stop but I don’t think it made a difference.
user28682125 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.