How Do I Perform A Continuous Check On Andorid Of The Returned Value Of Another Class?
Solution 1:
Why not create some kind of Listener (interface) ?
Small and basic example,
myGame = newMyGame(false, 30, newAndroidLeaderboard());
myGame.setGameOverListener(this);
Note: You don't need a setGameOverListener
method, you could also change your constructor to have a listener argument.
The listener would look like this:
interfaceGameOverListener {
abstractpublicvoidnotifyGameOver();
}
And create a method in side you MyGame object:
setGameOverListener(GameOverListener gol){
this.gol = gol;
}
And your Activity would implement that listener, and in the notifyGameOver()
method you would open the activity.
Like this:
publicvoidnotifyGameOver(){
startActivity(new Intent(HelloWorldAndroid.this, MainActivity.class));
}
To notify that your game is over just let your MyGame object call the notifyGameOver()
method:
gol.notifyGameOver();
Solution 2:
This seems like very bad design to me. Instead, I would recommend creating an interface OnGameOverListener
that has one method, onGameOver()
. The MyGame
class has an instance of this interface that clients can set. Then, when the MyGame
class decides the game is over, it can call onGameOver()
Look at the observer pattern
Post a Comment for "How Do I Perform A Continuous Check On Andorid Of The Returned Value Of Another Class?"