I am developing a camera application using latest Camera 2 API, and I have a button in my app to choose front facing camera and back facing camera on each button click.
Code for that is:
switch_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
//isfrontcam=true;
try {
manager.openCamera("0",mStateCallback,mBackgroundHandler);
} catch (SecurityException e) {
e.printStackTrace();
} catch (CameraAccessException e) {
e.printStackTrace();
}
} else if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
// isfrontcam = true;
try {
manager.openCamera("1", mStateCallback, mBackgroundHandler);
} catch (SecurityException e) {
e.printStackTrace();
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
My problem is app will minimizing automatically when I click the button to select camera.The above snippet is executing on button click. I could not understand the reason for this bug. Can anyone help?