是否可以在Android中恢复中断的Thread
?
答案 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)