Thread
是否可以在 Android中恢复中断?
问问题
2282 次
2 回答
3
您不应该通过其 API 恢复 Thread,resume()
方法已弃用(原因)。
您可以通过杀死线程并启动一个新线程来模拟恢复线程:
/**
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();
}
}
于 2013-03-11T20:08:47.900 回答