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.
You can force your threads to close by keeping a public
close()method inside your class that extends Thread:Now whenever you navigate to another screen you just need to call the
MyConnectionThread.closeConnection()method to force-close this Thread.See Also:
how-to-abort-a-thread-in-a-fast-and-clean-way-in-java
How can we kill the running thread in java?
Hope these will be helpful for you.