Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resume an interrupted Thread

Is it possible to resume an interrupted Thread in Android?

like image 668
NullPointer Avatar asked Apr 21 '26 21:04

NullPointer


1 Answers

You shouldn't resume Thread by its API, resume() method is depracated (reason).

You can simulate resuming Thread by killing it and starting a new one:

/**
Since Thread can't be paused we have to simulate pausing. 
We will create and start a new thread instead. 
*/
public class ThreadManager
{
    private static GameThread gameThread = new GameThread();

    public static void setRunning(boolean isRunning)
    {
        if (isRunning)
        {
            gameThread = new GameThread();
            gameThread.setRunning(true);
            gameThread.start();
        }
        else
        {
            gameThread.setRunning(false);
        }
    }

    public static boolean isRunning()
    {
        return gameThread.isRunning();
    }

    public static void join() throws InterruptedException
    {
        gameThread.join();
    }
}
like image 151
Adam Stelmaszczyk Avatar answered Apr 24 '26 12:04

Adam Stelmaszczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!