How to get location updates without using the service

Is there an alternative to running a service to get location updates?

+3
source share
1 answer

You can use PendingIntent like this -

Intent intent = new Intent(CUSTOM_INTENT);
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);

    manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);

Your broadcast receiver must have an intent filter for CUSTOM_INTENT in the manifest file

+5
source

All Articles