Search code examples
androidlayoutsurfaceviewvoid

Android: from surfaceview back to the menu


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.


Solution

  • 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);
        }
        ....