Android: Will the new thread just stop after it finishes?

Will the thread just terminate after its completion?

This is how I initialize my thread:

new Thread(new Runnable() { public void run() { } }).start(); 

Basically, what I'm trying to do is just do one task in a new thread and then end the thread. However, after a while I will start another one, etc. I don’t want a lot of threads to start, and I wonder if the thread will end after it completes?

Thanks.

+6
source share
2 answers

Yes. When run returns, the thread will stop.

To complete a single task in a thread on Android, you may need to use AsyncTask . AsyncTask designed specifically for this purpose. This gives you an easy way to transfer data to another stream and transfer the progress updates and the final result back to the main stream. Each AsyncTask is similar to Thread , but with these additional features.

+7
source

Will the thread just terminate after its completion?

Yes, it will complete and shut down after the run() method completes

+3
source

All Articles