I am using Android loopj Async Task to access data from the server.
I am trying to implement this in an autocompleteText view, that is, when it will search for custom types in my database and display the result in the ListView adapter. Everything is working fine.
But I need to cancel all previous requests when starting a new task. those. if the user enters "che", then the new AsyncHttpClient starts and starts the web service, then the user enters "chem", then I need to cancel all previous / running AsyncHttpClients. I
Any idea?
Here is my code
public void getValues(String movie){
AsyncHttpClient client = new AsyncHttpClient();
RequestParams webparams = new RequestParams();
webparams.put("fn", "searchMovies");
webparams.put("movie", movie);
client.post(domain, webparams, new AsyncHttpResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onSuccess(String response) {
try {
JSONObject obj = new JSONObject(response);
...
...
}
catch {}
@Override
public void onFailure(Throwable e, String response) {
Toast.makeText(SearchActivity.this,"Error Occured ! Please try again.",Toast.LENGTH_SHORT).show();
cd.goHome(SearchActivity.this);
}
});
}
source
share