I'm quite new in mobile development and also in JAVA language and I'm havin a big trouble now, because android 11 is comming to a lot of devices and I need to update the classes of a project to stop using AsyncTask (which is deprecated) but I quite dont understand how to update the following class to stop using AsyncTask, can anyone help me please?
obs: I'm brasilian so there are some words in portuguese :P
public class ChecarStatusTask extends AsyncTask<Context, Void, JsonObject> {
private Context context;
public AsyncResponse delegate;
@Override
protected JsonObject doInBackground(Context... params) {
context = params[0];
JsonObject json = new JsonObject();
Network net = new Network(context);
boolean deveMostrarProblemaConexao = DashboardActivity.deveMostrarProblemaConexao(context);
boolean problemaInternet = true;
//-- verify if connected
json.addProperty("Rede", "NO CONNECTION");
if (net.isNetworkAvailable()) {
json.remove("Rede");
json.addProperty("Rede", "OK");
}
//checking http with google
json.addProperty("Internet", "NO CONNECTION");
if(Network.checkHttpStatus("https://google.com")) {
json.remove("Internet");
json.addProperty("Internet", "OK");
problemaInternet = false;
}
if(!deveMostrarProblemaConexao && problemaInternet) {
return json;
}
return json;
}
@Override
protected void onPostExecute(JsonObject result) {
try {
delegate.processFinish(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}