从Activity到另一个打开SurfaceView的Activity

时间:2018-05-17 12:33:24

标签: android android-activity surfaceview

我有一个活动,这是我的菜单,我尝试打开另一个打开SurfaceView的活动。

我的问题是,使用按钮和onClickListener,我无法启动游戏。而我的另一个问题是,通过SurfaceView调用从Context返回菜单会导致游戏崩溃。

这是我的课程,可以打开SurfaceView

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GLSurfaceView= new GLSurfaceView(this);
    GLSurfaceView.context=this;
    setContentView(GLSurfaceView);
}

我尝试打开其他活动的菜单类

protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menue);

    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener(){
       @Override
       public void onClick(View view) {
           Intent Intent = new Intent(Menue.this ,MainActivity.class);
           startActivity(Intent);}
});

我的SurfaceView

public GLSurfaceView(Context context) {
    super(context);
    renderer = new Renderer();
    setRenderer(renderer);

    setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}

0 个答案:

没有答案
相关问题