问题
I am using Fused Api for location update. I am using Fused Api with Activity is working fine. But when i use it within service class its showing This is my Service class code . Where error occurring
回答1:
Class Task (https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) have three overloads of method addOnCompleteListener:
addOnCompleteListener(OnCompleteListener<TResult> listener)addOnCompleteListener(Activity activity, OnCompleteListener<TResult> listener)addOnCompleteListener(Executor executor, OnCompleteListener<TResult> listener)
Your Service is neither Activity, nor Executor. So the two latter overloads are not applicable for you. Just drop the first parameter and use it like that:
mFusedLocationClient!!.lastLocation.addOnCompleteListener { task ->
//do something
}
来源:https://stackoverflow.com/questions/45322675/fusedlocationproviderclient-with-service-android-kotlin