Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need gameover activity

I'm new to android, and I'm trying my best to create a game. I'm trying to create a gameover screen for my game, and I though the best way to do that was to create an activity for a gameover screen. However, I'm not sure how to go about doing this.The problem seems to be that I cannot create an intent anywhere other than the activity class. So I can't see when the game should end, and then create a new activity without it being in the activity class. So I'm having trouble connecting my game model to my activity class, so that when the player dies, it would trigger a gameover activity. Where in my activity class should I put this information?

like image 410
Athos Avatar asked Jul 19 '26 21:07

Athos


1 Answers

You would place code such as (assuming your activity is GameOverScreen extends Activity):

Intent gameOverScreen = new Intent(this, GameOverScreen.class);
startActivity(gameOverScreen);

To do so from outside the activity (since startActivity() is a public method of the Activity class), you'd just do like this, using the instance of your game activity that I call gameScreen in this example:

Intent gameOverScreen = new Intent(gameScreen, GameOverScreen.class);
gameScreen.startActivity(gameOverScreen);

You should probably have a reference to the instance of your game activity stored to the model as a Context object at least for resources.

like image 194
Ribose Avatar answered Jul 22 '26 12:07

Ribose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!