2012-11-28 44 views
2

返回主活動我不明白,我的主要活動和OpenGL渲染之間的流動。安卓:從GLSurfaceView

當我的應用程序啓動後,用戶將看到,我已經有一個按鈕,說做了一個非常漂亮的佈局「開始呈現。」當用戶點擊按鈕時,他/她將被轉移到繪製真棒圖片的渲染器視圖。然後,當圖片完成後,我想返回到主屏幕(帶按鈕的那個),但我不知道如何。

我打過電話從GLRenderer的setContentView(R.layout.activity_run),但顯然這是行不通的。然後我嘗試創建一個函數Run.endRendering(),它是一個靜態方法,並在GLRenderer中調用。 Run.endRendering()應該調用的setContentView(R.layout.activity_run),希望它將然後調用視圖返回到主屏幕,但由於R.endRendering()是一個靜態方法,它不能調用setContentView()的非靜態方法。

所以現在我完全失去了。有人能對這個問題有所瞭解嗎?

這些是我的骨架。

主要活動:

public class Run extends Activity 
{ 
    private GLSurfaceView glSurface; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_run); 

     // in here I mess with the main layout view the user 
     // is supposed to see. when he/she clicks on a button 
     // he/she will be transferred to the opengl view 

     // on button click: 
     glSurface = new GLSurfaceView(this); 
     glSurface.setRenderer(new GLRenderer()); 

     setContentView(glSurface); 
    } 
} 

而且渲染:

public class GLRenderer implements Renderer 
{ 
    // onSurfaceCreated, onDrawFrame, onSurfaceChanged, etc. 

    // the action happens here. From here I want to return to 
    // the main activity that created this renderer. 
} 
+2

使用2個活動,一個用於您的主,另一個用於您的Open GL。 – Carnal

回答

0

有一件事你可以做的是使該活動的佈局的你GLSurfaceView一部分。 活動的UI線程繼續運行。在其中創建一個處理程序,它將負責從佈局中刪除GLSurfaceView並顯示正常的非opengl視圖。

Handler mainHandler = new Handler() { 
    public void handleMessage(Message msg) { 
     // remove surfaceview from layout and show non-opengl views 
    } 
}; 

然後,您可以將您的活動(可能使用接口)的引用傳遞給GLRenderer。哪個可以打電話。

activity.mainHandler.sendMessage(msg)