How To Release Camera After Activity Ends In Android?
I am working on an application that requires to scan a QR code and click pictures, but sometimes it so happens that the camera application crashes and it says that the Android Came
Solution 1:
Put Below code in your onDestroy
method of your activity:
protected void onDestroy(){
if(camera!=null){
camera.stopPreview();
camera.setPreviewCallback(null);
camera.release();
camera = null;
}
}
If you are using separate Preview class then add below code in that:
public void surfaceDestroyed(SurfaceHolder holder) {
if(camera!=null){
camera.stopPreview();
camera.setPreviewCallback(null);
camera.release();
camera = null;
}
}
Post a Comment for "How To Release Camera After Activity Ends In Android?"