Hey, I have a question about how I can get back from a SurfaceView I created to the original view. (In this case back to the menu). I have a game class looking like this:
When the StartGame button is pressed I call this class:
This sets the view to a new Panel (surfaceview), like this:
And here I does alot of things (the whole game). But when the game is over I want to go back to the menu. But I dont know how to do this. I tried a few things, but havent got any to work. The hardware "back"-button on my phone does this perfectly, but how can I do it with code? Would really love some help!
Thanks! /Nick
Code:
public class game extends Activity {
/** Called when the activity is first created. */
static Context cont;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cont = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button StartGameButton = (Button)findViewById(R.id.StartGame);
StartGameButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent StartGameIntent = new Intent(game.this, StartGame.class);
startActivity(StartGameIntent);
}
});
When the StartGame button is pressed I call this class:
Code:
public class StartGame extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Panel(game.cont));
}
}
This sets the view to a new Panel (surfaceview), like this:
Code:
public class Panel extends SurfaceView implements SurfaceHolder.Callback {
public Panel(Context context) {
super(context);
mThread = new ViewThread(this); //This starts the gameloop
//code
}
}
And here I does alot of things (the whole game). But when the game is over I want to go back to the menu. But I dont know how to do this. I tried a few things, but havent got any to work. The hardware "back"-button on my phone does this perfectly, but how can I do it with code? Would really love some help!
Thanks! /Nick