google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

Crash when restarting the fragment with the Cameraview on Galaxy S8/Android 8.0 #242

Closed DinoMC closed 6 years ago

DinoMC commented 6 years ago

In my app, after taking a picture, the user is sent to a new fragment showing the picture taken. He can press the back button to go back to the previous fragment and take a different picture.

This works correctly on most of the test phones, but not on the one running Android 8.0 (a Samsung Galaxy S8). I tried in the Android 8.0 emulator in Android Studio and the issue isn't there, so this might be something specific to the phone. The app crash with the following stacktrace : java.lang.RuntimeException: Failed to start camera session at com.google.android.cameraview.Camera2.startCaptureSession (Camera2.java:486) at com.google.android.cameraview.Camera2$1.onOpened (Camera2.java:75) at android.hardware.camera2.impl.CameraDeviceImpl$1.run (CameraDeviceImpl.java:139) at android.os.Handler.handleCallback (Handler.java:789) at android.os.Handler.dispatchMessage (Handler.java:98) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:6938) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

Is this a Cameraview bug or some bad handling on my part?

I call mCameraView.stop(); onStop and OnPause and mCameraView.start(); onResume and OnCreateView.

Edit : got a more detailled stacktrace after running it in android studio with the same phone (updated above). Turns out this might be a duplicate of #53?

DinoMC commented 6 years ago

Confirmed duplicate of #53, proposed fix there solved the issue here.