Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close a WP7 application programmatically? [duplicate]

Possible Duplicate:
Windows Phone 7 close application

How do I programmatically close a WP7 application?

like image 508
Vercas Avatar asked Dec 02 '10 18:12

Vercas


4 Answers

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.

like image 135
Syed Umar Ahmed Avatar answered Oct 15 '22 22:10

Syed Umar Ahmed


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.

like image 30
Mick N Avatar answered Oct 15 '22 20:10

Mick N


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.

like image 7
driis Avatar answered Oct 15 '22 22:10

driis


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.

like image 5
moonlightdock Avatar answered Oct 15 '22 20:10

moonlightdock