J'ai une application Android qui utilise une tâche asynchrone pour valider les informations de connexion. Le onpostexecute n'est jamais atteint et je ne peux pas y ajouter @Override pour le faire fonctionner. Quand j'essaye de @Override, eclipse dit qu'il doit surcharger une méthode d'un supertype. Voici le code.Tâche asynchrone Android n'atteignant pasPostExecute
public class UserLoginTask extends AsyncTask <LoginObject, Void, Boolean>
{
@Override
protected void onPostExecute(Boolean result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
}
@SuppressWarnings("finally")
@Override
protected Boolean doInBackground(LoginObject... params)
{
// TODO: attempt authentication against a network service.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://softeng.cs.uwosh.edu/students/cs342g6/login.php");
Boolean response = false;
try
{
//Convert the login object to XML
XStream xstream = new XStream(new DomDriver("UTF-8"));
xstream.alias("Login", LoginObject.class);
String xml = xstream.toXML(login);
// Pass the XML as a StringEntity
StringEntity se = new StringEntity(xml,HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
System.out.println("MADE IT TO RESPONSE");
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
String resp = EntityUtils.toString(resEntity);
System.out.println(resp);
response = convertToBool(resp);
if(response)
System.out.println("true");
else
System.out.println("false");
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return response;
}
}
protected void onPostExecute(Boolean success)
{
System.out.println("In onPostExecute");
mAuthTask = null;
showProgress(false);
if (success)
{
finish();
}
else
{
mPasswordView
.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}
Votre problème est probablement lié à deux méthodes 'onPostExecute()'. Vérifiez-le. – Sajmon