0
I’m starting to work with Asynctasks and I don’t know much yet. I created a class that extends Asynctask and implemented the method doInBackground()
, but my question now is how do I get the return of this method?
In another class in the method efetuarLogin()
, I make a call for the method execute()
, but it does not return me to String that should return.
How can I get the return of the Ackground method?
I 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 calling class extending from 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;
}
So you are using Asynctask synchronously. Asynctask’s get() method only returns when the Asynctask() method is finished.
– ramaral