Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9036625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:02:57+00:00 2026-06-16T09:02:57+00:00

I am using AsyncTask Class to handle images that are coming from the server

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:02:58+00:00Added an answer on June 16, 2026 at 9:02 am

    I Found the Solution for this.
    If anyone facing the same issue.
    I Added new lines

    if (loadimage != null)
     {
       loadimage.cancel(true);
       loadimage = null;
    }
    
    loadimage.cancel(true) will stop the AsyncTask if it is already Running
    

    then execute the AsycTask()

    loadimage = new LoadImage();
    loadimage.execute();
    

    In this way i am able to call only last AsyncTask that what I required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a code which download the apk from server by using Asynctask, Currently
i am using asynctask to fetch images from given url.these images are displaying in
I have a question on using AsyncTask class provided by Android sdk. I am
I'm using an AsyncTask class to download data from a php file. After downloading,
I'm using an AsyncTask class to add, remove and clear items from my ArrayAdapter
I am trying to design a helper class that implements methods using AsyncTask. public
I have a method that is executed using asyncTask with a progressdialog. After this
How to create and update listview using AsyncTask getting data from server.Actually i am
I do have a problem working with my application. I am using AsyncTask class
I am getting images from background process by using url.To dispaly images i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.