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 6033111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:10+00:00 2026-05-23T05:26:10+00:00

Every time the user presses a button, the following code is executed. new Thread()

  • 0

Every time the user presses a button, the following code is executed.

new Thread() {
    @Override
    public void run() {
        aA = new albumArt(foo.getField("albumArt"),albumArt.GLOSSY_1, albumart,getBaseContext());
        runOnUiThread(new Runnable() {
            public void run() {
                    aA.placeAlbumArt();
            }
        });
    }
}.start();

There’s a problem with this:

For example:
User presses the button => Image A starts to get downloaded.
User presses the button (before Image A has finished) => Image B starts to get downloaded.

Image B finishes (before Image A) to get downloaded and then it’s shown (with aA.placeAlbumArt()).
Image A finishes and replaces Image B.

How can I avoid that Image A replaces Image B if it finishes later?

I mean, is there any way I can cancel a Thread (Image A) if another one (Image B) gets started before the first one finishes?

That would also help not to queue a lot of clicks and doing the whole process uselessly. I mean, if the user presses the button before Image A has finished, there’s no point in finishing to process Image A. If the user presses the button 5 times before Image A finishes, there’s no point in downloading Image A, B, C and D. It should only download E (the fifth click).

  • 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-05-23T05:26:11+00:00Added an answer on May 23, 2026 at 5:26 am

    If you were to use an AsyncTask then you could cancel it. You should be able to swap your Thread out for an AsyncTask without too much trouble.

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

Sidebar

Related Questions

Every time a user posts something containing < or > in a page in
I need to start a program every time the user logs in, but I
I would like to save the programs settings every time the user exits the
I have a photo gallery I would like that every time a user does
I'm writing a Word/VBA macro for a document template. Every time a user saves/creates
Every time I create a new project I copy the last project's ant file
Every time I turn on my company-owned development machine, I have to kill 10+
Every time I create an object that has a collection property I go back
Every time I need to work with date and/or timstamps in Java I always
I have a class that fetches data in response to button presses in the

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.