I started a new thread to upload photos from the phone mobile to a computer webserver.
if (CMenu.retCommand == transferer)
{
thrdTrsfr = new Thread(this);
thrdTrsfr.start();
}
public void run() {
if (Thread.currentThread() == thrdTrsfr)
{
if (vButtonPhotos.size() > 0)
transfererPhotos("http://192.168.1.123/imfmobile/photoj2meupload/uploadphoto.php");
else
afficheAlert("Aucune photo à transférer !");
}
}
When the upload is finished then I stopped the thread. I tested the number of active threads before the upload. When I tested the number of running threads after stopping the upload thread, the number does not change. I must navigate back to the main screen then the number of active thread is the same at before the upload. I use this code to stop the upload thread :
if (thrdTrsfr != null && thrdTrsfr.isAlive())
{
thrdTrsfr.interrupt();
thrdTrsfr = null;
}
So why must I go to the main screen in order to get the thread stopped?
Could it be that
transfererPhotos()is not finishing, perhaps due to waiting for an IO read of bytes that never arrives? If so, then the thread will stay alive forever, or until interrupted (as you are doing).BTW, I can’t see any value to the test for current thread: