2012-07-25 25 views
2

我正在通過使用表面視圖內的可運行線程來播放動畫。當我第一次運行應用程序時,一切正常,動畫正常播放。當我按回/ home按鈕並重新打開應用程序時,我得到一個沒有動畫的黑屏,但可運行的線程在我使用Log cat條目確認的背景上工作。Surfacecreate方法不會在onResume for Android上調用Surfaceview

此外,我重寫後退按鈕按下事件和完成()後面的按鈕按下事件內部調用。

任何人都可以幫我解釋爲什麼在恢復應用程序時沒有調用surfacecreated方法?

注:當我使用

android.os.Process.killProcess(android.os.Process.myPid()); 

後退按鈕事件,而不是結束()方法中,應用程序正常工作中的onResume事件。

在此先感謝,蒂姆

回答

0

我想,你必須擴展SurfaceView類和surfaceChanged method.And聽的方法再次戰平。 代碼:

class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback{ 
     SurfaceHolder holder; 
     public MySurfaceView(Context context) { 
      super(context); 
      holder = this.getHolder(); 
      holder.addCallback(this); 
     } 
     public void surfaceChanged(SurfaceHolder holder, int format, int width, 
       int height) { 
      //when surfaceChanged,i think you must make your view draw one time. 

     } 
     public void surfaceCreated(SurfaceHolder holder) { 
      //surfaceCreated 
     }  
     public void surfaceDestroyed(SurfaceHolder holder) { 
      //surfaceDestroyed 
     } 

    } 

希望這可以幫助你。