0

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.

Onur A.
  • 3,007
  • 3
  • 22
  • 37
Samarth
  • 47
  • 5

1 Answers1

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);
    }
    ....
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • i want to go from te surfaceview to te menu... i can go from menu to surfaceview.. want to go to menu from surface view – Samarth Apr 20 '13 at 11:47
  • 1
    ok so you should get a Context object from your MainActivity and then when you want to go back to menu just put this line on the gameover state context.setContentView(_yourlayoutid_); – Onur A. Apr 20 '13 at 20:52