I have a background service for listening location update using FusedAPI.
public class ListenLocation extends Service
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
} ... //code continues for location listener
I am starting this service from inside a fragment using
getActivity().startService(new Intent(getActivity(),ListenLocation.class));
All this is working fine and i am getting the location updates in background.
But how to stop this service once the application has been closed by the user ?
i tried the following but it's not stopping the service
getActivity().stopService(new Intent(getActivity(),ListenLocation.class));
What is the method to stop such service ?