I was reading Android CameraX codelab: https://codelabs.developers.google.com/codelabs/camerax-getting-started#4
The simplified code snippet is like this: