java - How to release camera when camera is opened? -


my app controls camera , there have been lot of crash reports devices cannot open camera. pressing button releases camera disables background mode. pressing home button doesn't release camera, causes crash when opening camera, , yet enables background mode.

how can release camera when camera app opened?

when use android hardware camera in android application should release other application or application can use it. practice release camera before moving activity in app.

use below code -

protected void ondestroy(){    if(camera!=null){         camera.stoppreview();         camera.setpreviewcallback(null);          camera.release();         camera = null;     } } 

above code release hardware camera,which open using camera.open(); method.

and if have custom preview have use in side surfacedestroyed method -

public void surfacedestroyed(surfaceholder holder) {      if(camera!=null){         camera.stoppreview();         camera.setpreviewcallback(null);          camera.release();         camera = null;     } } 

hope you.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -