I am using Android loopj Async Task for accessing data from server.
I am trying to implement this on an autocompleteText view , ie when user types it will search in my database and listout the result in a ListView using adapter. All are working fine.
But I need to cancel all previous requests when a new task run. ie if user type "che" then new AsyncHttpClient run and start web service, then user type "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) {
//dialog.dismiss();
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);
}
});
}