I'm starting to work with AsyncTasks and I still do not know much. I created a class that extends AsyncTask and implemented the doInBackground()
method, but my question now is how do I get the return of this method?
In another class in the efetuarLogin()
method, I make a call to the execute()
method, but it does not return me the String that should return.
How can I get the method return from the InBackground?
Thank you in advance for your cooperation!
protected String doInBackground(String... params) {
String resposta = "";
try {
resposta = this.sendGet(params[0]);
} catch (Exception e) {
e.printStackTrace();
}
return resposta;
}
Method that calls the class that extends AsyncTask:
public Usuario efetuarLogin(String email, String senha){
JSONStringer js = new JSONStringer();
ConexaoHttp conexao = new ConexaoHttp();
try {
js.object();
js.key("email").value(email);
js.key("senha").value(senha);
js.endObject();
} catch (JSONException e) {
e.printStackTrace();
}
String usuario = conexao.execute(js.toString()); // não retorna uma String, dá erro dizendo que ele retorna um objeto do tipo AsyncTask
return null;
}