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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:10:01+00:00 2026-05-28T01:10:01+00:00

ImageThread it = new ImageThread(this.imageURL,this); Thread t = new Thread(it); t.start(); I’m new to

  • 0
ImageThread it = new ImageThread(this.imageURL,this);

        Thread t = new Thread(it);
        t.start();

I’m new to threads and had to implement the above in my field that loads an image, because it slowed down the UI thread.

Whether my threads are downloading an image or some json content, they appear to still be downloading even though the user has pushed a new mainscreen onto the uiapplication. This continuous loading could be a problem if a user enters a screen and then accesses another in quick succession. As a result, the last screen they are on only finishes its thread when the others are done.

What am I supposed to do with my threads that would be deemed responsible? I don’t want my app to be bogged down by a queue of threads. How do I, say, cancel downloads on screen change?

I’m posting this question in Java since I think the process is the same.

  • 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-28T01:10:02+00:00Added an answer on May 28, 2026 at 1:10 am

    You can force your threads to close by keeping a public close() method inside your class that extends Thread:

    private class MyConnectionThread extends Thread {
            /** determines whether the thread is runnuing or not. */
            private boolean alive = false;
            private HttpConnection hconn = null; // or whatever connection method you want to use ( SocketConnection etc.)
            private InputStream inputStream = null; // or DataInputStream etc...
    
            public MyConnectionThread() {
                alive = false;
                // ...
                // ...
            }
    
            public void run() {
                alive = true;
                try {
                    String connection_parameter = ";deviceside=false"; // [For BlackBerry: ] this parameter is for connection using MDS, need to add different parameters for different connection methods.
                    hconn = (HttpConnection) Connector.open("http://your_url.com"+connection_parameter);
                    int response = hconn.getResponseCode();
                    if (response == HttpConnection.HTTP_OK) {
                        inputStream = hconn.openInputStream();
    
                        // process the result here by reading the inputStream ...
                        // ...
                        // ...
                    }
    
                    inputStream.close();
                    hconn.close();
    
                }catch(Exception excp) {
                    // Handle Exceptions here...
                }catch (Throwable e) {
                   // Exception in reading inputStream
                }finally{
                    alive = false;
                    this.interrupt();
                }
            }
    
            /**
             * Forces the connection to close anytime.
             */
            public void closeConnection() {
                alive = false;
                try {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    inputStream = null;
                    if (hconn != null) {
                        hconn.close();
                    }
                    hconn = null;
                    this.interrupt();
                } catch (Exception excp) {
                    // Handle Exception here...
                    System.out.println("Exception in closing HttpConnection: " + excp.toString());
                }
            }
        }
    

    Now whenever you navigate to another screen you just need to call the MyConnectionThread.closeConnection() method to force-close this Thread.

    See Also:

    1. how-to-abort-a-thread-in-a-fast-and-clean-way-in-java

    2. How can we kill the running thread in java?

    3. How to Stop a Thread or a Task

    Hope these will be helpful for you.

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

Sidebar

Related Questions

I made a image thread class that runs the update method in the instance
Posted this over at the Drupal forums but haven't received a response. Basically, I
I have an application that uses images from web a a source. for my
I have been working on an object class for my iPhone app that lazy
I have a List of the location of images on a folder. I have
I am writing an application where the user can change the color of the
The following is encoded JSON data from a PHP webpage. { { news_date =
I have a java app which runs just fine (on Ubuntu 10.04) for few
What are the differences between JAI's FileLoad/FileStore operations and its ImageRead/ImageWrite operations? Is one
What I want to do is copy an images 'source' or 'html elements' to

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.