How can a thread in Android be stopped?
Answer
There are 2 following ways preferred to stop a thread.
Answer
There are 2 following ways preferred to stop a thread.
- Create a volatile boolean variable and change its value to false and check inside the thread. volatile isRunning = false; public void run() { if(!isRunning) {return;} }
- Or you can use the interrupt() method which can be receive inside a thread.