1
我正在製作一款Android遊戲,其中包含一個名爲Game的Activity,一個名爲GameView的SurfaceView和一個名爲GameThread的Thread。遊戲的onCreate(),我創建了一個新的GameView,它創建了一個新的GameThread,其中執行了所有的遊戲邏輯和畫布繪製。按下回家並重新啓動後,Android遊戲變爲空白
但是,我有一些生命週期困難。當我按下並重新啓動它時,它工作正常,但是當我按回家並重新啓動時,我看到的只是一個空白屏幕。這裏是GameView的onSurfaceCreated()和onSurfaceDestroyed():
@Override
public void surfaceCreated(SurfaceHolder holder) {
mThread.mRunning = true;
mThread.mWidth = getWidth();
if(mThread.mWidth > 550) mThread.mWidth = 550;
mThread.mHeight = getHeight();
try {
mThread.start();
} catch(IllegalThreadStateException e) {
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Wait for the secondary thread to end before finishing
boolean retry = true;
mThread.mRunning = false;
while (retry) {
try {
mThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
謝謝。在onResume中創建SurfaceView使其工作。 – cstack 2010-04-08 13:35:17
活動「重新啓動」時您的SurfaceView爲空嗎?你的線程如何,你是否必須重新開始?我不確定如何明確創建SurfaceView會有所幫助,也許我不明白。 – Flynn81 2010-06-30 04:12:13
請分享你的代碼我有同樣的問題 – 2011-05-25 09:39:01