Android Question Camera crashes on device rotation

Cosmo

Member
Hello all,

rotating my device causes my app to crash in line 9 (in orginal code line 273).
But the class instance is initialized before in public sub StartCamera.

Any suggestions about this behavior?

Thanks in advance,
Bernhard


B4X:
Private Sub Camera1_Preview (CData() As Byte)
    
    If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
        'Dim n As Long = DateTime.Now
        Dim frameBuilder As JavaObject
        Dim bb As JavaObject
        bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(CData))
        frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
        Dim cs As CameraSize = camEx.GetPreviewSize
        frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))
'        frameBuilder.RunMethod("setImageData", Array(bb, 400, 300,  842094169))
        Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
        Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
        LastPreview = DateTime.Now
        Dim Matches As Int = SparseArray.RunMethod("size", Null)
        If Matches > 0 Then
            Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(0))
            Dim raw As String = barcode.GetField("rawValue")
            Dim numstr As String = raw.SubString2(1,11).As(Int).As(String)
            If edit_papnr.Text <> numstr Then
                edit_papnr.Text=numstr
                Dim b As Beeper
                b.Initialize(100,1600)
                b.Beep
            End If
'            FoundBarcode(raw)
        End If
    End If
End Sub

1701241015318.png
 

Cosmo

Member
And initialized in StartCamera:

B4X:
Public Sub StartCamera
'    btoast.Show("start camera")
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        btoast.Show("Keine Berechtigung.")
        Return
    End If
'    btoast.Show("camera permission ok")
    
    pnlPreview.Visible = True
    
    camEx.Initialize(pnlPreview, False, Me, "Camera1")           
    Wait For Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters
        camEx.StartPreview
'        btoast.Show("camera started")
    Else
        btoast.Show("Fehler Start Kamera")
        StopCamera
    End If
End Sub
 
Upvote 0
Top