Android: from surfaceview back to the menu

坚强是说给别人听的谎言 提交于 2019-12-08 11:56:39

问题


I am making a simple game in which I draw a set of bitmaps on a Canvas on SurfaceView. Now in my main activity I have a LinearLayout where I have designed a button. In the onClick() of this button I write:

setContentView(new surfaceviewclass(this));

it works fine. It opens the SurfaceView and I play the game etc. But I want to see the button again where I started from I mean when the game is over I want the menu to reappear.. I have already tried calling the void like

main.menu();

but the app crashes.. please help.


回答1:


Make a new activity class and write this in onCreate() method of it

setContentView(new surfaceviewclass(this));

and in the previous activity create an Intent and start this new activity when button is clicked

e.g ....// onclick method of btn on old activity
    {
        Intent i=new Intent(OldClass.this, NewClass.class);
        startActivity(i);
    }
    ....


来源:https://stackoverflow.com/questions/16118285/android-from-surfaceview-back-to-the-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!