Android Question [SOLVED] GPS not working after HttpJob

epneeh

Member
Hi
Experiment block:
Sub Activity_Resume
    '//try experiment ------------------
    If alreadyversioncheck = False Then
       
        Dim j As HttpJob
        j.Initialize("",Me)
        j.Download("https://somesite.com/pvt/maps/ver.php")
        Wait For (j) jobdone(j As HttpJob)
        If j.Success Then
            Dim cloudver As Int = j.GetString
            If versi <> cloudver Then
               
                ToastMessageShow("Update your apps",True)
            End If
        Else
            ToastMessageShow("Koneksi error",True)
        End If
        j.Release
        alreadyversioncheck = True
    End If
    '//try experiment ------------------
   
    If Label1.Text = "" Then
        ProgressDialogShow2("Loading location...",False)
    End If
   
    If Starter.gps1.GPSEnabled =False  Then
        StartActivity(Starter.gps1.LocationSettingsIntent)
        Return
    Else
        Wait For MapFragment1_Ready
        log("Map is ready")
        gmap = MapFragment1.GetMap
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then

       Else 

       End If
    End If
End Sub

If i add httpjob before checking gps is on or off, code execution stop at line 26, but when i remove httpjob (line 2 until 21) gps work fine, any help appreciate. Thanks in advance.
 
Last edited:

epneeh

Member
Sori erel i've updated the code, see line 32, i think mapFragment1 is never ready, this is my log
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is that this line: Wait For MapFragment1_Ready is called long after the event was raised.

Change your code to:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
    Wait For MapFragment1_Ready
    Log("====Map is ready====")
    gmap = MapFragment1.GetMap
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        gmap.MyLocationEnabled = True
        If gmap.IsInitialized Then
            Do While gmap.MyLocation.IsInitialized = False
                Sleep(100)
            Loop
            Dim cp As CameraPosition
            cp.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude,15)
            gmap.AnimateCamera(cp)
        End If
    End If
End Sub

Sub Activity_Resume
    
    '//try experiment -----------------
    Dim j As HttpJob
    j.Initialize("",Me)
    j.Download("https://epneeh.com/pvt/maps/ver.php")
    Wait For (j) jobdone(j As HttpJob)
    If j.Success Then
        Dim cloudver As Int = j.GetString
        If versi <> cloudver Then
               
            ToastMessageShow("Update your apps",True)
        End If
    Else
        ToastMessageShow("Koneksi error",True)
    End If
    j.Release
    If Starter.gps1.GPSEnabled =False  Then
        StartActivity(Starter.gps1.LocationSettingsIntent)
        Return
    End If

End Sub
 
Upvote 0

epneeh

Member
The problem is that this line: Wait For MapFragment1_Ready is called long after the event was raised.

Change your code to:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
    Wait For MapFragment1_Ready
    Log("====Map is ready====")
    gmap = MapFragment1.GetMap
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
       
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        gmap.MyLocationEnabled = True
        If gmap.IsInitialized Then
            Do While gmap.MyLocation.IsInitialized = False
                Sleep(100)
            Loop
            Dim cp As CameraPosition
            cp.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude,15)
            gmap.AnimateCamera(cp)
        End If
    End If
End Sub

Sub Activity_Resume
   
    '//try experiment -----------------
    Dim j As HttpJob
    j.Initialize("",Me)
    j.Download("https://epneeh.com/pvt/maps/ver.php")
    Wait For (j) jobdone(j As HttpJob)
    If j.Success Then
        Dim cloudver As Int = j.GetString
        If versi <> cloudver Then
              
            ToastMessageShow("Update your apps",True)
        End If
    Else
        ToastMessageShow("Koneksi error",True)
    End If
    j.Release
    If Starter.gps1.GPSEnabled =False  Then
        StartActivity(Starter.gps1.LocationSettingsIntent)
        Return
    End If

End Sub
thanks erel it solved now, i put Wait For MapFragment1_Ready right after load its layout, you're the man
 
Upvote 0
Top