Jabez Magomere
02/03/2020, 1:32 PMSean Keane
02/03/2020, 1:33 PMNirmal
02/03/2020, 1:36 PMJabez Magomere
02/03/2020, 1:54 PMclass CoroutineIntentServiceHelper @Inject constructor(private val farmerRepository: FarmerRepository) : CoroutineScope{
private val job = Job()
override val coroutineContext: CoroutineContext
get() = job + <http://Dispatchers.IO|Dispatchers.IO>
fun postUnsyncedFarmers() = launch {
farmerRepository.postUnsyncedFarmers()
}
fun clear(){
job.cancel()
}
}
In the intent service;
coroutineIntentServiceHelper.postUnsyncedFarmers();
//When the service is destroyed, cancell any running operations
@Override
public void onDestroy() {
coroutineIntentServiceHelper.clear();
}
Sean Keane
02/03/2020, 2:13 PMNirmal
02/03/2020, 9:10 PM