Guest
New Member
Hi all... Long time lurker here.
I am trying to get Erel his Geofence demo to update a simple label text value (Geofence tutorial used is this one: https://www.b4x.com/android/forum/threads/geofence-monitoring-a-region-in-the-background.84767/ )
The demo has 3 modules. Main, GeofenceService and Starter. I have only made changes to Main and Starter.
I have added to the Starter module
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The Geofence_Enter sub looks like so (added result = Id and StartActivity(Main) )
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The Geofence_Exit sub looks like so (Again added result = Id and StartActivity(Main) )
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
In the Main module I added to Erls code.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
And added some test Geofence locations with geo.id 1, 2 and 3 (replaced the true GPS locations in the example below)
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Obviously I also created a main layout with a label named lblGeo in/on it.
The Sub Activity_Resume looks like this.
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The ToastMessageShow in Geofence_Enter and Geofence_Exit are working (most of the times), and the lblGeo.Text does get update (again most of the times) when starting the app in the corresponding location, however it does not change when moving to another location. That is until is restart the app..
I'm sure that I am making a beginners ID 10 T mistake, and hope some one here can show me what.
Thank you, and please stay safe!
			
			I am trying to get Erel his Geofence demo to update a simple label text value (Geofence tutorial used is this one: https://www.b4x.com/android/forum/threads/geofence-monitoring-a-region-in-the-background.84767/ )
The demo has 3 modules. Main, GeofenceService and Starter. I have only made changes to Main and Starter.
I have added to the Starter module
			
				B4X:
			
		
		
		Sub Process_Globals
    Dim result As String
    result = "0"
End SubThe Geofence_Enter sub looks like so (added result = Id and StartActivity(Main) )
			
				B4X:
			
		
		
		Public Sub Geofence_Enter (Id As String)
    Log("Enter: " & Id)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo("Enter: " & Id, "Enter", Main)
    n.Notify(1)
    ToastMessageShow("Enter: " & Id, True)
    result = Id
    StartActivity(Main) 'show the main activity again
End SubThe Geofence_Exit sub looks like so (Again added result = Id and StartActivity(Main) )
			
				B4X:
			
		
		
		Public Sub Geofence_Exit (Id As String)
    Log("Exit: " & Id)
    ToastMessageShow("Exit: " & Id, True)
    result = Id
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo("Exit: " & Id, "Exit", Main)
    n.Notify(2)
    StartActivity(Main) 'show the main activity again
End SubIn the Main module I added to Erls code.
			
				B4X:
			
		
		
		Sub Globals
    Dim lblGeo As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    lblGeo.Visible = True
    AddGeofence
End SubAnd added some test Geofence locations with geo.id 1, 2 and 3 (replaced the true GPS locations in the example below)
			
				B4X:
			
		
		
		Sub AddGeofence
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
'TEST LOCATION 1
        Dim geo As Geofence
        geo.Initialize
        geo.Id = "1"
        geo.Center.Initialize2(xx.392218, y.208352) 'THUIS!
        geo.RadiusMeters = 100
        geo.ExpirationMs = DateTime.TicksPerDay 'expire after one day
        CallSubDelayed3(GeofenceService, "AddGeofence", Me, geo)
        Wait For Geofence_Added (Success As Boolean)
        Log("Geofence added: " & Success)
'TEST LOCATION 2
        Dim geo As Geofence
        geo.Initialize
        geo.Id = "2"
        geo.Center.Initialize2(xx.390509, y.208845)
        geo.RadiusMeters = 100
        geo.ExpirationMs = DateTime.TicksPerDay 'expire after one day
        CallSubDelayed3(GeofenceService, "AddGeofence", Me, geo)
        Wait For Geofence_Added (Success As Boolean)
        Log("Geofence added: " & Success)
'TEST LOCATION 3   
        Dim geo As Geofence
        geo.Initialize
        geo.Id = "3"
        geo.Center.Initialize2(xx.391098, y.212085)
        geo.RadiusMeters = 100
        geo.ExpirationMs = DateTime.TicksPerDay 'expire after one day
        CallSubDelayed3(GeofenceService, "AddGeofence", Me, geo)
        Wait For Geofence_Added (Success As Boolean)
        Log("Geofence added: " & Success)
    End If
End SubObviously I also created a main layout with a label named lblGeo in/on it.
The Sub Activity_Resume looks like this.
			
				B4X:
			
		
		
		Sub Activity_Resume
    If Starter.result = "0" Then
        lblGeo.Text = "No data"
    End If
    If Starter.result = "1" Then
        lblGeo.Text = "location 1"
    End If
    If Starter.result = "2" Then
        lblGeo.Text = "location 2"
    End If
    If Starter.result = "3" Then
        lblGeo.Text = "location 3"
    End If
End SubThe ToastMessageShow in Geofence_Enter and Geofence_Exit are working (most of the times), and the lblGeo.Text does get update (again most of the times) when starting the app in the corresponding location, however it does not change when moving to another location. That is until is restart the app..
I'm sure that I am making a beginners ID 10 T mistake, and hope some one here can show me what.
Thank you, and please stay safe!
			
				Last edited: