1

i am making a game on android.. i have a main activity..where i have made my main menu in a void menu() and just called it in on create

menu();

in that the play button has a on clicklistener..

public void onClick(View v){
//if play is pressed
setContentView(new gamescreen(this));
}

this works fine and i can play te game as welll... but now i have a gameover screen designed in main activity as well.. when in surface view te game is over...i want this gameover screen to appear how do i do it?

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
Samarth
  • 47
  • 5
  • 1
    You should use more than one Activity, as your application contains more than one user screen. – Egor Apr 20 '13 at 12:25
  • please explain? even if i have several activities how am i supposed to call them in surface view? – Samarth Apr 20 '13 at 12:46

1 Answers1

2

in your gamescreen class define a static boolean variable which holds whether game is over, and back in your main activity create a handler which will check status of gameover variablee you declared back in your gamescreen class, and whenever it detects gameover variabl true it will change screen by this

setContentView(new gameover(this));
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • i will try that thanks.. but were am i supposed to call the if statement? in on create? – Samarth Apr 21 '13 at 02:08
  • yes, just put your handler and this code in onCreate() method so it will work on UI thread and work out as you want, also you can check this post, it seems helpful http://stackoverflow.com/questions/16118285/android-from-surfaceview-back-to-the-menu/16119461?noredirect=1#comment23036819_16119461 – Onur A. Apr 21 '13 at 10:16