sedran
sedran

Reputation: 3566

How can I close a javascript metro style app?

Is there a code to exit from the metro style application? In C#, C++, or VB, there are examples like CoreApplication.Exit() but I couldn't find something like that for Javascript.

Upvotes: 1

Views: 1727

Answers (3)

pwlodek
pwlodek

Reputation: 403

You can call MSApp.terminateApp function. Details here: http://msdn.microsoft.com/pl-pl/library/windows/apps/hh770781.aspx

Upvotes: 0

The general recommendation is that apps do not provide their own close affordances. In your example, closing automatically in response to a loss of network connectivity will appear as if the app crashes under such conditions. As such, it may not actually pass Windows Store certification on that point along (see requirements, section 3.2 about apps that end unexpectedly). Furthermore, section 3.6 prohibits apps closing themselves as already noted, so you'll fail on that as well.

Calling window.close will generate a crash report that appears within the Windows Store dashboard, and will be logged as an app crash, in fact (this may end up counting against the app in the Store--not sure about that, but I wouldn't risk it). In this case, it's better to use MSApp.terminateApp because the crash report will be much more comprehensive (and you can include your own info). Still, MSApp.terminateApp should only be used for truly unrecoverable conditions.

If you have a condition under which the app can't continue to run effectively, but isn't a crash, per se, like the loss of network connectivity, it's better to inform the user of that condition and let them decide whether to close the app (through Alt +F4 or the top-down swipe close gesture) in response. You should also detect when network connectivity has been restored and continue, of source. This way the app hasn't lost its state and can continue where it left off, thereby providing a contiguous user experience.

Upvotes: 3

JP Alioto
JP Alioto

Reputation: 45117

There is really no explicit "closing" in the Application Lifecycle of a Metro style app.

Generally, users don't need to close apps, they can let Windows manage them. However, users can choose to close an app using the close gesture or by pressing Alt+F4. You can't include any UI in your app to enable the user to close your app, or it won't pass the Store certification process.

You should handle Suspending and Resuming correctly and allow the user to control explicit closing of your application (there is a gesture to close a Metro style app in Windows 8, there is no need to provide a visual affordance like a button).

Upvotes: 2

Related Questions