java - How to check if android.hardware.Camera is released? -


i got exception while releasing camera object "java.lang.runtimeexception: method called after release"

following code , exception stack trace.

if (camera != null) {      camera.stoppreview();                     camera.release();      camera = null; } 

exception stack trace -

java.lang.runtimeexception: method called after release() thread[main,5,main] android.hardware.camera._stoppreview(native method) android.hardware.camera.stoppreview(camera.java:626) com.s5.selfiemonkey1.activity.preview.surfacedestroyed(preview.java:152) android.view.surfaceview.updatewindow(surfaceview.java:601) android.view.surfaceview.access$000(surfaceview.java:88) android.view.surfaceview$3.onpredraw(surfaceview.java:183) android.view.viewtreeobserver.dispatchonpredraw(viewtreeobserver.java:680) android.view.viewrootimpl.performtraversals(viewrootimpl.java:2123) android.view.viewrootimpl.dotraversal(viewrootimpl.java:1139) android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4872) android.view.choreographer$callbackrecord.run(choreographer.java:776) android.view.choreographer.docallbacks(choreographer.java:579) android.view.choreographer.doframe(choreographer.java:548) android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:762) android.os.handler.handlecallback(handler.java:800) android.os.handler.dispatchmessage(handler.java:100) android.os.looper.loop(looper.java:194) android.app.activitythread.main(activitythread.java:5371) java.lang.reflect.method.invokenative(native method) java.lang.reflect.method.invoke(method.java:525) com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833) com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 

it stoppreview() called on released object.

i had made method return me boolean depending of whether camera in use or not. below small snipet:

    public static camera checkforcamera(){     camera camera = null;     try {         camera = camera.open(); // line throw exception if camera not in use.     }     catch (exception e){         // if exception thrown, return boolean value here...     }     return camera; // if instance of camera, if not available return null. } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -