Navigator.app.exitApp () does not work

I am developing a Windows Phone 8 PhoneGap. Using navigator.app.exitApp () I quit the application from the main screen on the Windows 7 phone. But when I tried the same on the Windows 8 phone, I get the error message Unable to get property 'exitApp' of undefined or null reference . I would like to know why this is undefined in a Windows 8 phone and not in the Phone Phone Phone Phone 7. In addition, I would like to know if there is a way to exit the application programmatically in the Windows Phone 8 PhoneGap app ?.

+6
source share
7 answers

You can create a simple plugin. Add the ExitApp.css file to your platforms / wp 8 / Plugins folder with:

 using System.Windows; namespace WPCordovaClassLib.Cordova.Commands { class ExitApp : BaseCommand { public void execute(string options) { Application.Current.Terminate(); } } } 

edit your platforms / wp 8 / config.xml and add to the widget tag:

 <feature name="ExitApp"> <param name="wp-package" value="ExitApp" /> </feature>` 

then from you javascript call:

 cordova.exec(null, null, "ExitApp", "execute", []); 

You can use it in combination with the "backbutton" event to close the application when the user clicks on the button on the main page:

 function goBack(e){ if(isInMyMainPage()) cordova.exec(null, null, "ExitApp", "execute", []); } document.addEventListener("backbutton", goBack, false) 
+9
source

I am developing a small application for Windows Phone 8.1, and the code below works for me:

 window.close(); 
+1
source

Navigator.app.exit() will not exit the application, this will cause the application to crash.

On Windows Phone 8, it is handled, so it just throws an exception.

You will need to write the code below in the page_BackKeyPress event in CordovaView.xaml.cs

 Application.Current.Terminate(); 

It will exit the application when you click on the hardware stand.

0
source

A similar question here: How to exit an application in Windows Phone 8 using a phone call 2.3 includes a fix that does not require any hacking of its own.

0
source

In version 3.6.3, navigator.app.exitApp () works.

Called in CordovaView.cs here

 void CordovaBrowser_ScriptNotify(object sender, NotifyEventArgs e) { string commandStr = e.Value; string commandName = commandStr.Split('/').FirstOrDefault(); if (browserDecorators.ContainsKey(commandName)) { browserDecorators[commandName].HandleCommand(commandStr); return; } CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr); if (commandCallParams == null) { // ERROR Debug.WriteLine("ScriptNotify :: " + commandStr); } else if (commandCallParams.Service == "CoreEvents") { switch (commandCallParams.Action.ToLower()) { case "overridebackbutton": string arg0 = JsonHelper.Deserialize<string[]>(commandCallParams.Args)[0]; this.OverrideBackButton = (arg0 != null && arg0.Length > 0 && arg0.ToLower() == "true"); break; case "__exitapp": Debug.WriteLine("Received exitApp command from javascript, app will now exit."); CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); CordovaBrowser.InvokeScript("eval", new string[] { "setTimeout(function(){ cordova.fireDocumentEvent('exit'); cordova.exec(null,null,'CoreEvents','__finalexit',[]); },0);" }); break; case "__finalexit": IsExiting = true; // hide the browser to prevent white flashes, since about:blank seems to always be white CordovaBrowser.Opacity = 0d; CordovaBrowser.Navigate(new Uri("about:blank", UriKind.Absolute)); break; } } else { if (configHandler.IsPluginAllowed(commandCallParams.Service)) { commandCallParams.Namespace = configHandler.GetNamespaceForCommand(commandCallParams.Service); nativeExecution.ProcessCommand(commandCallParams); } else { Debug.WriteLine("Error::Plugin not allowed in config.xml. " + commandCallParams.Service); } } } 
0
source

navigator.app.exitApp (); was available in Apache Cordova WP8 projects with 3.4.0

 <div onclick="navigator.app.exitApp()">Exodus</div> 
0
source

A similar question here: https://groups.google.com/forum/#!msg/phonegap/9v2kOwXj6sQ/O8SVpd-qjicJ

But basically it says that applications for Windows Phone 8 should not be programmatically completed.

-1
source

Source: https://habr.com/ru/post/950636/


All Articles