0
I have this method to read an html page, and it’s doing a toast with the result. But I wanted him to return the value read to me, or put it in some variable, but I did not succeed.
private class GrabURL extends AsyncTask<String, Void, Void> {
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(getActivity());
protected void onPreExecute() {
Dialog.setMessage("Carregando. Aguarde...");
Dialog.show();
}
protected Void doInBackground(String... urls) {
try {
HttpGet httpget = new HttpGet(urls[0]);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
Content = Client.execute(httpget, responseHandler);
} catch (ClientProtocolException e) {
Error = e.getMessage();
cancel(true);
} catch (IOException e) {
Error = e.getMessage();
cancel(true);
}
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
if (Error != null) {
Toast.makeText(getActivity(), Error, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), "Source: " + Content, Toast.LENGTH_LONG).show();
retorno = Content; // Essa variavel retorno é onde queria setar.
}
}
}
Thanks was that. Now came another question, I can control the maximum time to perform this function?
– Gabriel Duarte
You have some alternatives to achieve this. If you want to know more details, open a new question in the Portuguese OS.
– Piovezan