I have an IntentService
that starts an asynchronous task in another class and should then be waiting for the result.
The problem is that the IntentSer
My favorite option is to expose two similar methods, for example:
public List getDogsSync();
public void getDogsAsync(DogCallback dogCallback);
Then the implementation could be as follows:
public List getDogsSync() {
return database.getDogs();
}
public void getDogsAsync(DogCallback dogCallback) {
new AsyncTask>() {
@Override
protected List doInBackground(Void... params) {
return getDogsSync();
}
@Override
protected void onPostExecute(List dogs) {
dogCallback.success(dogs);
}
}.execute();
}
Then in your IntentService
you can call getDogsSync()
because it's already on a background thread.