Ali
Ali

Reputation: 2042

Resume an interrupted Thread

Is it possible to resume an interrupted Thread in Android?

Upvotes: 3

Views: 2414

Answers (2)

Adam Stelmaszczyk
Adam Stelmaszczyk

Reputation: 19837

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();
    }
}

Upvotes: 3

madlymad
madlymad

Reputation: 6530

Thread does not support these actions as related methods are deprecated.

Upvotes: 0

Related Questions