1

how to check if we already call fusedLocationProviderClient.requestLocationUpdates(locationRequest, pendingIndent); ? because if we call it again then any previously registered requests that have the same PendingIntent (as defined by equals(Object)) will be replaced by this request.

zeus
  • 12,173
  • 9
  • 63
  • 184

1 Answers1

0

Will FLAG_NO_CREATE do the trick?

        Intent intent = new Intent(context, Receiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_NO_CREATE);
        if(pendingIntent != null){
            //requestLocationUpdates()
        }
P. Suvajac
  • 29
  • 4
  • No, because if i do fusedLocationProviderClient.removeLocationUpdates(pendingIntent); then the fusedLocationProviderClient is not listening anymore any location update but the pendingindent is still here :( – zeus Sep 30 '18 at 07:55
  • Then you can track progress with a field in SharedPreferences or in local DB. When you call requestLocationUpdates() set filed to true and once you call removeLocationUpdates() set it to false. You can access this field anywhere in the app to check if you should make a new location request. – P. Suvajac Sep 30 '18 at 08:42