Restarting an app through code

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
I have an app for a simple game, and I want to have a New Game button that will basically restart the app, just as if the user were to close it and then open a new instance (in other words, there are no scores or settings or anything, just the user saying I want to play again). As I mentioned, this can obviously be achieved by having the user close and then re-open the app, but I want to have a button to do this (much more convenient for the user). My app is only one page (MainPage.xaml/MainPage.xaml.vb), so I was thinking about possibly having the button call the page's New() method. Will this give the same result as opening a new instance would? Thanks.
 
I don't know anything about development for phones or the like, but in principle I don't see why you'd close the program to reset it. Just run a subroutine that resets all of your variables and controls to the defaults they had when the program was loaded. For example if I click new game in Windows Chess, it doesn't close the program. It just puts the king, queen and other pieces back where they belong at the start.
 
I don't know anything about development for phones or the like, but in principle I don't see why you'd close the program to reset it. Just run a subroutine that resets all of your variables and controls to the defaults they had when the program was loaded. For example if I click new game in Windows Chess, it doesn't close the program. It just puts the king, queen and other pieces back where they belong at the start.

That was pretty much my question. I do NOT want to need to close the app, that is what I am asking about. I know that I could reset all my variables and properties in a method, but because of all the properties of elements and controls that get modified, I wanted to know if there is a simple method or technique to restart the app so that I don't need to worry about forgetting to reset any variables or properties (or, for that matter, accidentally reset any of them to the wrong values). If the app can figure out what everything should be when it starts based on the XAML and New method, shouldn't I have some way to say "Figure it out again"?
 
Back
Top