Skip to content

Instantly share code, notes, and snippets.

@jyaunches
Created September 27, 2012 18:15
Show Gist options
  • Save jyaunches/3795510 to your computer and use it in GitHub Desktop.
Save jyaunches/3795510 to your computer and use it in GitHub Desktop.
public class SendMessageTask extends SafeAsyncTask<Boolean> {
private final HttpClient httpClient;
private final sendMessageCallbacks sendMessageCallbacks;
@Inject
public SendMessageTask(org.apache.http.client.HttpClient httpClient,
@Assisted SendMessageCallbacks sendMessageCallbacks {
this.httpClient = httpClient;
this.sendMessageCallbacks = sendMessageCallbacks;
}
@Override
public Boolean call() throws Exception {
// make network call
// return true or false based on whether it was successful
// You could also make an object that wraps the response code or something
return true;
}
@Override
protected void onException(Exception e) {
LOG.error("Error when ending session", e);
sendMessageCallbacks.onMessageSendingFailed("Exception occured: " + e.toString());
}
@Override
protected void onSuccess(Boolean wasSuccessful) {
if(wasSuccessful){
sendMessageCallbacks.onMessageSendingSuccess("Message sending successful") :
}else{
sendMessageCallbacks.onMessageSendingFailed("Message sending failed");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment