Reputation: 1
Cannot resolve method 'requestLocationUpdates(String, int, int, LocationListener)'
try {
locationManager = (LocationManager) requireActivity().getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,3,locationListener);
}
catch (Exception e){
e.printStackTrace();
}
when wrote this code it give me error why it happen I am not understand when I use the the dot after locationManager
there are 9 function overloading and I used .requestLocationUpdates(String provider,minTimeMs,minDistanceM,locationListner );
but still getting error please anyone help me.
.requestLocationUpdates(String provider,minTimeMs,minDistanceM,locationListner );
I am using right one still getting if iam wrong one use please tell me
Upvotes: 0
Views: 79
Reputation: 6510
You have missed an argument in what you wrote. There is no method overloaded for requestLocationUpdates with just four arguments. There is, however, this one:
public void requestLocationUpdates (String provider,
long minTimeMs,
float minDistanceM,
Executor executor,
LocationListener listener)
which I think is the one you were trying to invoke. Notice there is an extra argument of Executor type.
There is an explanation about the Executor in the documentation:
Executor: the executor handling listener callbacks This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
So in your case, you would need to add it to your call:
try {
locationManager = (LocationManager) requireActivity().getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
3000L,
3.0f,
Context.getMainExecutor().
locationListener);
}
catch (Exception e){
e.printStackTrace();
}
Upvotes: 0