1

I started working with the new camera2 API.

I run a camera preview on a TextureView in my first Activity. Via my navigation drawer can I start a second Activity. I want this one to show me a camera preview in a TextureView, too. Unfortunately, the screen stays white and I don't see a picture. I don't know the error and couldn't find something about it:

5278-5414/de.application E/CameraDeviceGLThread-0﹕ Received exception on GL render thread:
    java.lang.IllegalStateException: swapBuffers: EGL error: 0x300d
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:487)
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:480)
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:681)
            at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:103)
            at android.os.Handler.dispatchMessage(Handler.java:98)
            at android.os.Looper.loop(Looper.java:211)
            at android.os.HandlerThread.run(HandlerThread.java:61) 06-01 23:00:44.258    5278-5414/de.application I/CameraDeviceState﹕ Legacy camera service transitioning to state ERROR

I start the new Activity pretty simple, and the functions for the camera are in both Activitys more or less the same.

Intent i = new Intent(MainActivityOld.this, FullScreenActivity.class);
startActivity(i);

Can you imagine a mistake I make? Do I have to stop the first Camera Preview somehow?

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Natjo
  • 2,005
  • 29
  • 75

1 Answers1

1

Generally, a TextureView tears down its SurfaceTexture output when it is no longer displayed. So when your first Activity goes into the background, the TextureView is no longer a valid target for camera data.

How were you intending to send preview data to your second Activity's TextureView? You'll need to switch the flow of preview buffers to target the second TextureView when the switchover occurs. You can do this by creating a new camera capture session that targets the second TextureView, when you switch to the second activity.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • I do that, I start everything new and treat the new activity just like the first activity and use the same algorithm to start the camera as in the first activity. Is my mistake, that I don't end the camera capture session in the first activity? – Natjo Jun 03 '15 at 16:51
  • Yes, you generally need to shut down the camera instance if the activity it is in is no longer visible. This can sometimes be avoided, but requires special handling - if your code is identical in both activities, then shutting down the camera in the first activity is the safest option. – Eddy Talvala Jun 09 '15 at 20:19