I am sending location data using co routines in workmanager. I tried just using the workmanager but it does not do async work I tried ListenableWorkmanager but that was too complicated for me so I am trying to use coroutines.
override fun doWork(): Result {
CoroutineScope(IO).launch {
val location = work()
fusedLocationClient!!.removeLocationUpdates(locationCallback)
string = logData(location)
}
return if(JSONObject(string).get("status") == "1"){
Result.success()
}else{
Result.retry()
}
}
I am having trouble on how to return the location from the work
function
private suspend fun work():Location{
...............
fusedLocationClient!!.lastLocation.addOnSuccessListener { location ->
if (location != null) {
mCurrentLocation = location
// how do I send this location back to the fuction??
}
}.addOnFailureListener {
mLog.i(TAG, it.message)
}
return mCurrentLocation // if I do this could be a null right?
}