Android Question Camera2 with activity error: signature does not match expected signature

juacochero

Member
Licensed User
Longtime User
Hi everyone!
I can run Erel's tutorial with Camera2 without any problems, but I want to be able to use it in an activity, as the rest of my project was not built in B4XPages.
But I get a "java.lang.Exception: Sub activity_pause signature does not match expected signature" error when pausing the activity.

My relevant part of the code is the following. The rest is exactly like the tutorial, and the libraries are the same (CamEx2 and Camera2 v1.11)
Anyone knows how to deal with the error?
Thank you!


B4X:
Sub Globals
    Private Root As B4XView
    Private xui As XUI
    Private frontCamera As Boolean = False
    Private VideoMode As Boolean = False
    Private VideoFileDir, VideoFileName As String
    Private MyTaskIndex As Int
    Private rp As RuntimePermissions
    Private cam As CamEx2
    Private pnlCamera As B4XView
    Private pnlBackground As B4XView
    Private btnEffects As Button
    Private btnScene As Button
    Private buttons As List
    Private btnAutoExposure As Button
    Private btnFocus As Button
    Private ProgressBar1 As ProgressBar
    Private openstate, busystate As Boolean
    Private btnRecord As Button
    Private btnMode As Button
    Private btnCamera As Button
    Private barZoom As SeekBar
    Private B4XImageView1 As B4XImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    Activity.LoadLayout("StillPicture")
    VideoFileDir = rp.GetSafeDirDefaultExternal("")
    VideoFileName = "1.mp4"
    cam.Initialize(pnlCamera)
    Log(cam.SupportedHardwareLevel)
    buttons = Array(btnScene, btnAutoExposure, btnEffects, btnFocus, btnMode)
    SetState(False, False, VideoMode)
End Sub

Sub OpenCamera (front As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission!", True)
        Return
    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", True)
    End If
End Sub

Sub Activity_Resume
    OpenCamera(frontCamera)
End Sub

Sub Activity_Pause
    Log("TI:" & cam.TaskIndex)
    cam.Stop
End Sub

Sub btnMode_Click
    VideoMode = Not(VideoMode)
    If VideoMode Then
        rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result = False Then
            ToastMessageShow("No permission!", True)
            VideoMode = False
        End If
    End If
    SetState(openstate, busystate, VideoMode)
    PrepareSurface
End Sub
 

drgottjr

Expert
Licensed User
Longtime User
you're missing:
B4X:
Activity_Pause (UserClosed As Boolean)

you just have:
B4X:
Activity_Pause
 
Upvote 1
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…