I write a program which needs to receive informations from a server. I use asynchronous threads to accomplish that. But when the user clicks on another item a new thread gets launched. If the first one has not yet finished for example because of a network issue, the second thread ends and sets the UI information. Then the first one ends and overwrites it again. So how can I stop the first thread when the user clicks on another item?
I got that:
Thread asyncThread = new Thread(task); asyncThread.start();
But from what I can see in the Thread object, there is no way to stop the thread (only deprecated .stop()), but I don't want to use deprecated stuff for new programs.