Android Question How to call a sub within same activity

AndroidMadhu

Active Member
Licensed User
Hello,
May be it is a silly question.
But I am not able to call a sub within the same activity.

I have written the below sub with the activity named (actmap)....
B4X:
Sub gps_check
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Starter.flp.IsConnected = False Then
        SetState("Location provider not available")
    End If
    If Result Then
        Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
        Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
        Dim sc As StatusCodes
        Select SettingsResult.GetLocationSettingsStatus.GetStatusCode
            Case sc.SUCCESS
                SettingsAreGood
            Case sc.RESOLUTION_REQUIRED
                SetState("RESOLUTION_REQUIRED")
                SettingsResult.GetLocationSettingsStatus.StartResolutionDialog("srd")
                Wait For srd_ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
                If LocationSettingsUpdated Then
                    SettingsAreGood
                Else
                    SetState("Not enabled")
                End If
            Case Else
                SetState("Not available")
        End Select
    Else
        SetState("No permission")
    End If
End Sub

Now I am calling the above sub [gps_check] within the same activity

B4X:
Sub MapFragment1_Click (Point As LatLng)
    CallSub(actmap,"gps_check")
End Sub

The below error I am getting

B4X:
actmap - 92: Undeclared variable 'actmap' is used before it was assigned any value.

Can anyone advice as what I am doing wrong?
 

DonManfred

Expert
Licensed User
Longtime User
If you are in the same activity. Why calling the sub with callsub? use wait for correctly
or just call the sub you want to use
B4X:
starter.CheckLocationSettingStatus()
Starter is always present so you directly can call subs there
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
f you are in the same activity. Why calling the sub with callsub? use wait for correctly
or just call the sub you want to use

Thank you @DonManfred .. it works great....

Thanks
 
Upvote 0
Top