Best way to configure AsyncTask for use in autocomplete search
<p>I am calling an AsyncTask in the onQueryTextChange method of a SearchView and displaying  the results in a list. The searching works, but occasionally tends to hang for a second if the user types quickly in the searchview. I want to further optimize this approach. Since its an autocomplete Search, as the user starting typing, several AsyncTasks gets queued for execution. But I am only interested in the very last searchrequest.</p>

<p>Currently, I am doing something like this</p>

<pre><code>if (myAsyncTask != null)
    myAsyncTask.cancel(true);

   myAsyncTask = new MyAsyncTask(context,URL);
</code></pre>

<p>Is there a better way to do this? I would like to do something like this, if possible</p>

<pre><code>myAsyncTask.executeOnExecutor(new OptimizedExectionerService);
</code></pre>

<p>The OptimizedExectionerService class should cancel all pending and runnning tasks in the pool and ONLY process the last request that was made.</p>