android – 应用程序冻结Camera.Release()

我在Android市场开发者控制台中收到了我的应用程序的错误日志.报告冻结的原因是“ANR keyDispatchingTimedOut”我在用户在相机释放后接受图像后将其追溯到一行代码.按下按钮以接受图像的代码如下:

case R.id.ib_good: // good picture, exit
        //create a new intent...
        Intent i = new Intent();
        i.putExtra("bitmap",path); // path to the temp image we saved

        setResult(RESULT_OK,i); // good job!
        // close the activity

        if (mCamera != null) {
            cv.setCamera(null);
            mCamera.release(); // this is the line that is causing the crash (EDIT: Line 115 in CameraActivity)
            mCamera = null;
        }


        finish();

        break

这是我在开发者控制台中获得的完整堆栈跟踪:

   DALVIK THREADS:
"main" prio=5 tid=1 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x4001d8c0 self=0xccc8
  | sysTid=20802 nice=0 sched=0/0 cgrp=default handle=-1345017816
  | schedstat=( 1781707766 981567374 1514 )
  at android.hardware.Camera.native_release(Native Method)
  at android.hardware.Camera.release(Camera.java:127)
  at com.rdesigns.targetCalc.CameraActivity.onClick(CameraActivity.java:115)
  at android.view.View.performClick(View.java:2405)
  at android.view.View$PerformClick.run(View.java:8813)
  at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4627)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  at dalvik.system.NativeStart.main(Native Method)

"Binder Thread #3" prio=5 tid=7 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x44d361c8 self=0x21ef38
  | sysTid=20808 nice=0 sched=0/0 cgrp=default handle=2265664
  | schedstat=( 6805422 24505615 31 )
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #2" prio=5 tid=6 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x44d1b600 self=0x11eef0
  | sysTid=20807 nice=0 sched=0/0 cgrp=default handle=1156104
  | schedstat=( 56304928 87432866 67 )
  at dalvik.system.NativeStart.run(Native Method)

"Binder Thread #1" prio=5 tid=5 NATIVE
  | group="main" sCount=1 dsCount=0 s=N obj=0x44d1a520 self=0x11f8c0
  | sysTid=20806 nice=0 sched=0/0 cgrp=default handle=1177728
  | schedstat=( 9429930 47668459 39 )
  at dalvik.system.NativeStart.run(Native Method)

"Compiler" daemon prio=5 tid=4 VMWAIT
  | group="system" sCount=1 dsCount=0 s=N obj=0x44d152a0 self=0x11fca0
  | sysTid=20805 nice=0 sched=0/0 cgrp=default handle=1179728
  | schedstat=( 99487306 115570068 507 )
  at dalvik.system.NativeStart.run(Native Method)

"Signal Catcher" daemon prio=5 tid=3 RUNNABLE
  | group="system" sCount=0 dsCount=0 s=N obj=0x44d151e8 self=0x11fee0
  | sysTid=20804 nice=0 sched=0/0 cgrp=default handle=1190192
  | schedstat=( 9216308 11657716 15 )
  at dalvik.system.NativeStart.run(Native Method)

"HeapWorker" daemon prio=5 tid=2 VMWAIT
  | group="system" sCount=1 dsCount=0 s=N obj=0x43769de8 self=0x1227f0
  | sysTid=20803 nice=0 sched=0/0 cgrp=default handle=1255400
  | schedstat=( 55267334 21697997 41 )
  at dalvik.system.NativeStart.run(Native Method)

我不知道应该怎么做才能解决这个问题……任何建议都表示赞赏!

解决方法:

在调用.startPreview之前你有没有在任何地方?
这是我的代码如何在应用程序内部使用CameraPreview发布相机.

 camera.setPreviewCallback(null); // PreviewCallback de_init.
 camera.stopPreview();            // stop Preview
 previewActive=false;             // lock_var for check if preview active or not 
 camera.release();                // and finaly release the camera after stop the preview

我希望那就是你要找的……

上一篇:java – JPanel在尝试绘制时冻结了我的整个应用程序


下一篇:vue长列表性能优化