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?
Share
You would place code such as (assuming your activity is
GameOverScreen extends Activity):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 callgameScreenin this example:You should probably have a reference to the instance of your game activity stored to the model as a
Contextobject at least for resources.