恢复中断的线程

时间:2013-03-11 20:04:47

标签: android multithreading

是否可以在Android中恢复中断的Thread

2 个答案:

答案 0 :(得分:2)

您不应该通过其API恢复线程,resume()方法已被删除(reason)。

你可以通过杀死它并开始一个新的线程来模拟恢复线程:

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

答案 1 :(得分:0)

Thread不支持这些操作,因为不推荐使用相关方法。