I am having an issue with creating a pop-up window. I have a game i’m developing, and I’m trying to have a window or sub-menu pop up after I’ve won the game so the user has an option of quitting or restarting. Everything I’ve seen on popup windows is done in the activity. I want to do this from my “controller” class, basically I want to check to see if the user has won within my logic class and if they did bring up a window, I have a feeling, I’m going to have to do this in my activity. Any help would be appreciated it. If you need any further details just let me know.
Share
You will have to do it in the Activity. You have two options:
1) When you know the game is over, have a method in your “controller” class that returns whether or not the popup should be displayed. Something like isGameWon(). Call this from your Activity and respond accordingly.
2) Keep a reference to your Activity in your controller class, or allow access to your Activity as a singleton object. When the game ends, check if the player won in your controller class, and if so, call a function in your Activity to display the popup, like showGameWonPopup().
You can’t display a popup outside of the UI Activity. Your two classes need to communicate about the end result of the game and respond accordingly.