2)
Call then service: StartService(ServiceName)
Ends the application: Activity.Finish
3)
In the service can check the change in location every x time
B4X:
Sub Service_Start (StartingIntent As Intent)
'GPS check code
'.....
'.....
'Calling new every n minutes
StartServiceAt ("", DateTime.Now + n * DateTime.TicksPerMinute, True)
'Calling new every n seconds
StartServiceAt ("", DateTime.Now + n * DateTime.TicksPerSecond, True)
'Note, only one line, or in minutes or seconds
end sub
3)
When you want to stop the service can do so:
B4X:
Sub Button1_Click
If IsPaused (NameService) = False Then ' checks if the service is running
CancelScheduledService (NameService) 'service removes the Schedule
StopService (NameService) ' Stop service
End If
end sub
The service is for the program to run in the background.
You put the program in place and activate the service and stops the application, but the service is ongoing.
From the service each x time (I put you before) you verify if the GPS changed. And when change, you call your application