从Web Intent返回,Android相机应用停止

时间:2014-03-02 12:47:43

标签: java android

我有一个扫描二维码的Android应用程序。然后通过显示网站的可点击链接显示结果。当我点击链接时,我将被重定向到网站,但当我点击我的手机上的后退按钮时,它应该返回到应用程序,但是有一个错误。它说app停止了。我认为当我从网站返回时,我没有处理活动的代码。

你能帮帮我吗?我该怎么办? 谢谢。 :)

03-02 20:58:53.454: E/AndroidRuntime(11165): FATAL EXCEPTION: main
03-02 20:58:53.454: E/AndroidRuntime(11165): java.lang.RuntimeException: Method called after release()
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.hardware.Camera.setPreviewDisplay(Native Method)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.hardware.Camera.setPreviewDisplay(Camera.java:519)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at net.sourceforge.zbar.android.CameraTest.CameraPreview.surfaceCreated(CameraPreview.java:63)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.SurfaceView.updateWindow(SurfaceView.java:605)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:237)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.View.dispatchWindowVisibilityChanged(View.java:8019)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1081)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1081)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1081)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1081)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1081)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1497)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1237)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5162)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.Choreographer.doCallbacks(Choreographer.java:591)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.Choreographer.doFrame(Choreographer.java:561)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.os.Handler.handleCallback(Handler.java:725)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.os.Looper.loop(Looper.java:176)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at android.app.ActivityThread.main(ActivityThread.java:5317)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at java.lang.reflect.Method.invokeNative(Native Method)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at java.lang.reflect.Method.invoke(Method.java:511)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
03-02 20:58:53.454: E/AndroidRuntime(11165):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

根据https://stackoverflow.com/a/15358323/1590950

public void onPause() {
    super.onPause();

    if (mCamera != null) {
        mCamera.setPreviewCallback(null);
        mPreview.getHolder().removeCallback(mPreview);   // you need this line
        mCamera.release();
    }
}