如果在picturecallback返回之前按下了电源按钮,相机会崩溃

时间:2015-07-10 11:22:37

标签: java android android-camera

以下问题:如果在调用getPictureCallback()方法之前按下拍照按钮后按下电源按钮,应用程序崩溃。

相机加载在这样的线程中:

private class CameraHandlerThread extends HandlerThread {
    Handler mHandler = null;

    CameraHandlerThread() {
        super("CameraHandlerThread");
        start();
        mHandler = new Handler(getLooper());
    }

    synchronized void notifyCameraOpened() {
        notify();
        runOnUiThread(new Runnable() {
            public void run() {
                setCameraParameter();
            }
        });
    }

    void openCamera() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                openAndroidCamera();
                notifyCameraOpened();
            }
        });
        try {
            wait();
        }
        catch (InterruptedException ex) {
            LogManager.e(TAG, ex.getMessage(), ex);
            CoreToastDialog.showErrorMessage(getString(R.string.FailedToLoadCamera));
        }
    }
}

我在onPause中断线程。任何想法如何解决这一问题?该错误仅在非常罕见的时间转换中发生 - 所以每30次尝试它可能只运行一次。

如果是PictureCallback,有什么方法可以解决这个问题吗?

错误讯息:

W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x410a32a0)
W/System.err﹕ java.lang.RuntimeException: Unable to start activity ComponentInfo{DeviceListView}: java.lang.NullPointerException
W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
W/System.err﹕ at android.app.ActivityThread.access$700(ActivityThread.java:140)
W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4921)
W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)

0 个答案:

没有答案