Android Question Camera fails takes just one shot


Active Member
Licensed User
with the camera library I can take a picture, but if I live my Layout which is in a panel (but not leave the activity), when I want to take a new shot, the last toastMessage at the end of this code appears.

camera library:
Sub OpenCamera (front As Boolean)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
    End If
    SetState(False, False, VideoMode)
    Wait For (cam.OpenCamera(front)) Complete (TaskIndex As Int)
    If TaskIndex > 0 Then
        MyTaskIndex = TaskIndex 'hold this index. It will be required in later calls.
        Wait For(PrepareSurface) Complete (Success As Boolean)
    End If
    Log("Start success: " & Success)
    SetState(Success, False, VideoMode)
    If Success = False Then
        ToastMessageShow("Failed to open camera, relaunch the app !", True)
    End If
End Sub

I'm obliged to relaunch my app. What can be wrong, because, I only do a 'visible-non visible' panel (the one which has the camera layout), that is to say that my camera should be always 'on' waiting for a new shot. But the behaviour here seems to indicate that the 'prepareSurface' fails.

Any way to solve this ?

José J. Aguilar

Licensed User

We need to know something else.
What camera library are you using and do you get some error in the logs?

Based in your code, I guess you're using Camera2

The configuration steps are:

1. Open the camera when the activity is resumed.
2. Prepare the surface and start preview. The preview size and capture size are set at this point.
3. Stop the camera when the activity is paused.

Due you're just showing/hiding a panel. Are you doing the step 3 when you hide the panel?
Upvote 0


Active Member
Licensed User
Hi José,

Thanks for your help.
I wrote

'openCamera(False) '
instead of
then the panel event closes it.

Now, it works well. You save me a lot. In a few moment, my app can be finished at all.
Thanks, thanks, thanks
Upvote 0