Possible Duplicate:
Windows Phone 7 close application
How do I programmatically close a WP7 application?
You can always call an exit by doing this at your landing page use this code on click of your application back button:
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}
This will remove back entries from the stack, and you will press a back button it will close the application without any exception.
Acknowledging known solutions to provide "Exit" buttons, currently I do not see a compelling reason to implement an "exit" from a WP7 application.
The platform is fully capable of managing closure of apps. The more apps don't provide an exit, the quicker users will become accustomed to not thinking about app house keeping, and let the platform manage it.
The user will just navigate their device using start, back, etc.
If the user wants out of the current app to go do something else quickly - easy - they just hit start.
.Exit(), whilst available for xna, really isn't required anymore either. There was a cert requirement during CTP that games had to provide an exit button. This is now gone.
Non game apps never had the need to implement this.
The more this topic's discussed (and it really has been given a good run around the block), the more the indicators to me suggest there is no need to code an exit.
It should also be mentioned the app cert reqts are specific that apps should not have unhandled exceptions.
There isn't really a good way to do it. There is a nice explanation/overview of your options here.
For short, if this is a Silverlight app (not XNA), it is not supported. You can simply throw an unhandled exception, and the app will quit. I wouldn't recommend that, it seems like a hack and a rather crude way of doing it.
Here is a way to make it look nicer, but at the end of the day it still throws an exception. I don't know if the application certification process looks at whether you are throwing unhandled exceptions, but I guess it could be an issue.
Simplest thing to do is simulate back from your root/home page. I'm guessing this is exactly what apps (those which have quit button) like Fruit Ninja do.
if ( NavigationService.CanGoBack )
{
NavigationService.GoBack();
}
Btw, above snippet works for a silverlight app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With