My program needs to take in a user's name as a String, and makes a call to the API to see if it exists. I made a method that takes in that string, and executes an async task to send the API call. But it looks like the comparison in my method is being executed before my async task finishes. What is the proper way to implement something like this
public boolean checkUser(String name) {
checkedName = name;
checkValidSummoner check = new checkValidSummoner();
check.execute();
if (checkedName == null) {
return false;
} else {
return true;
}
}
private class checkValidSummoner extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(String... strings) {
try {
checkedName = RiotAPI.getSummonerByName(checkedName).toString();
} catch (APIException e) {
checkedName = null;
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
}
}