-4

I want to send location even if app is in the background, for tracking the

driver location but it has to be stopped as cab arrived.

Intent svc = new Intent(this, BackgroundSoundServi.class);
startService(svc);
Ramesh sambu
  • 3,577
  • 2
  • 24
  • 39
Manasvi
  • 450
  • 7
  • 9
  • So what API do you trigger when the cab arrives at location? – Pranay Soni Jan 24 '18 at 12:57
  • 1
    can you please explain your question ! add code for background service etc and exactly where you got issue – Adil Jan 24 '18 at 13:03
  • 1
    `when there is not required to send location` - how do you know that there is no requirement? What is the condition? – Vladyslav Matviienko Jan 24 '18 at 13:10
  • Question is totally unclear . Anyway OP you can check [This thread](https://stackoverflow.com/questions/47804529/stop-a-service-after-mainactivity-is-closed-edited/47806235#47806235) to stop a running service . – ADM Jan 24 '18 at 13:17
  • 1
    Alright, prob is i am getting notification as train arriving lets suppose if i'm in range of 5 km i will get notify as i'm sending my location to the server, if i move out from this 5 km range my service automatically stop and if i move in this range my service automatically start sending my co-ordinates to the server. – Manasvi Jan 25 '18 at 05:38
  • auto start and stop service is quietly heard to detect when we have to do it, you need to check everytime with fixed Time interval in background service – Adil Jan 25 '18 at 06:29

1 Answers1

2

You should create a list of GeoPoints where the cab can be considered as "Arrived". Inside your Service's onLocationChange() method put a method that checks the distance with the current position of the cab and the destination points and you can turn off your service when the distance becomes shorter than a given radius. e.g. 100 meters. However, if you want service to start sending locations automatically when it departs, then you should not turn off the service, but just stop sending locations. The service should always check cabs position to destinations'.

MJakhongir
  • 2,101
  • 2
  • 16
  • 27