0

I have a service:

[Service]
public class LocationService : Service, ILocationListener
{
....

public override StartCommandResult OnStartCommand(...)
{ return StartCommandResult.Sticky; } 
}

Started in one of environment

new Task(() =>
{
Application.Context.StartService(new Intent(Application.Context, typeof(LocationService)));
}).Start();

How to stop this service from another place?

I tried to do this:

Application.Context.StopService(new Intent(Application.Context, typeof(LocationService))); 

but it does not always work

ssb.serman
  • 155
  • 1
  • 12

2 Answers2

1

These possible duplicates might solve your issue:

android LocationListener not stopping GPS use

android how to stop gps

Sounds like the big thing is making sure nothing is still requesting location updates.

Community
  • 1
  • 1
bstar55
  • 3,542
  • 3
  • 20
  • 24
0

the answer was here:

Stop Location Listener in Android

In my case its call method StopLocationUpdates

[Service]
public class LocationService : Service, ILocationListener
{
....

public override StartCommandResult OnStartCommand(...)
{ 
     return StartCommandResult.Sticky;
} 

public void StopLocationUpdates()
{
    LocManager.RemoveUpdates(this);
    LocManager= null;
}

}
Community
  • 1
  • 1
ssb.serman
  • 155
  • 1
  • 12