I have this method that is using the deprecated module AsyncTask:
private void createNewNote() {
AsyncTask<ContentValues, Void, Uri> task = new AsyncTask<ContentValues, Void, Uri>() {
@Override
protected Uri doInBackground(ContentValues... params) {
ContentValues insertValues = params[0];
Uri rowUri = getContentResolver().insert(Notes.CONTENT_URI, insertValues);
return rowUri;
}
@Override
protected void onPostExecute(Uri uri) {
mNoteUri = uri;
}
};
ContentValues values = new ContentValues();
values.put(Notes.COLUMN_COURSE_ID, "");
values.put(Notes.COLUMN_NOTE_TITLE, "");
values.put(Notes.COLUMN_NOTE_TEXT, "");
task.execute(values);
}
I would like to use a modern module instead of AsyncTask. I tried using
ExecutorService executor = Executors.newSingleThreadExecutor();
but the thing is I need to return a value from the Background task to the Main thread, and I didn't manage to do it with newSingleThreadExecutor. Do you have any solutions? (I want to keep things as close as possible to the actual solution).