1

I've created a simple Android app with two tabs (for now). The first tab contains a SurfaceView that has a its SurfaceHolder contain a Camera instance:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/camera_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
        <SurfaceView
            android:id="@+id/surface_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</FrameLayout>

However, I'm not sure if I should release the camera when the second tab is displayed. I tried doing this and the view lags around ~2 seconds on a Nexus 6 device every time I switch to and from the camera tab. Is it considered bad practice if I simply just keep the camera running, and is there a best approach to implement camera views with tabs?

I also tried if asynchronously loading the surface view/camera would be viable, but according to the Android Camera class reference:

This class is not thread-safe, and is meant for use from one event thread

I've also stumbled upon this similar SO question (for reference): https://stackoverflow.com/questions/28634291/android-which-tab-view-approach-for-cpu-heavy-camera-preview-tab-fragments

Community
  • 1
  • 1
Jack Sparser
  • 75
  • 2
  • 10

0 Answers0