I am using AsyncTask Class to handle images that are coming from the server to display it in the ImageView
I have one Next button in my code to call the next image using following code:
private class LoadImage extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
if (imgque != null) {
imgSelectedQue.setImageDrawable(imgque);
if (getActivity() != null) {
adjustResourceEnvelope();
}
}
}
@Override
protected void onPreExecute() {
imgque = null;
imgSelectedQue.setImageDrawable(null);
imgSelectedQue.requestLayout();
}
@SuppressWarnings("deprecation")
@Override
protected Void doInBackground(Void... params) {
InputStream is;
try {
is = (InputStream) new URL(Constants.PLAYER_SERVICE_BASE_URL + "/playerservice"
+ imageurl).getContent();
imgque = Drawable.createFromStream(is, null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
imgque = null;
e.printStackTrace();
}
return null;
}
}
Now the issue is that if I click the next button REPEATEDLY then it call the AsyncTask that many times and ImageView displaying all the images like “Slide-Show” because all the url images are in queue.
Is there any way to display only last AsyncTask call image?
I Found the Solution for this.
If anyone facing the same issue.
I Added new lines
then execute the AsycTask()
In this way i am able to call only last AsyncTask that what I required.