2011-01-25 62 views
4

我在android市場開發人員控制檯中收到了我的應用程序的錯誤日誌。它報告了一個凍結,其原因是「ANR keyDispatchingTimedOut」當用戶在相機獲釋後接受圖像後,我將它追溯到一行代碼。下面是按下按鈕接受圖像的代碼:應用程序凍結在Camera.Release()

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) 

我不知道我應該做些什麼來解決這個問題...任何意見表示讚賞!

回答

1

你有沒有在叫做.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 

我希望這是你在找什麼...

+0

謝謝,這可能是它。相機預覽不應該運行,因爲用戶剛剛拍攝了一張照片,但它可能正在某些設備的後臺運行。我會試着停止它,看看是否能解決問題。 – Matt 2011-01-25 19:00:05