How to exit or quit my Windows Phone 8 app programmatically? - windows-phone-8

I am developing a Windows Phone 8 application.
How can I exit or quit programmatically (through code) from my Windows Phone 8 app?
What are the various ways in which I can programmatically (through code) exit or quit from my Windows Phone 8 app?

In WP8 there's a new API which lets you terminate the application:
Application.Current.Terminate();
By calling the method your app will immediatelly terminate. However the Application_Closing event won't be called, and IsolatedStorageSettings.ApplicationSettings dictionary won't be automatically persisted.
So if you have data hanging around in IsolatedStorageSettings.ApplicationSettings that you don't want to lose then it's wise to save it:
IsolatedStorageSettings.ApplicationSettings.Save();
Application.Current.Terminate();
Also the method should not be misused. See http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.terminate(v=vs.105).aspx for more info for legitimate use cases.

while (((PhoneApplicationFrame)App.Current.RootVisual).CanGoBack)
{
((PhoneApplicationFrame)App.Current.RootVisual).RemoveBackEntry();
}

In Windows Phone 8.1, the method has been renamed to
Application.Current.Exit();

Related

Windows phone 8 pjsip audio routes to speaker phone instead of earpiece always

Ive build the sample pjsip library for windows phone and successfully registered and made a call.
butproblem is audio is always on speaker phone,not on earpiece ,
can anyone help to make the earpiece the default audio route always ?
Thanks
Access to audio routes is only allowed when a "Windows Voip Call" is active. This is achieved by calling the NotifyCallActive method on the VoipPhoneCall object. The VoipPhoneCall object is returned via a call to the RequestNewOutgoingCall method of the VoipCallCoordinator class. I've tried integrating PJSIP into the Windows Phone 8 voip framework but PJSIP is not able to run in the background process. Still trying to figure that one out.
You can't with the PJSip sample. If you search in pjmedia_audiodev you'll discover a TODO tag.
Also, the sample does not manage VoIP calls, therefore you can route to the earpiece.
I hope this helps.

Windows Phone Custom URI

in my windows phone 8 application i am using custom uri association to launch another application through my phone.
i.e
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
but my app is not able to get certified for store because of this. the testing team tells that you app terminates unexpectedly while executing this.
now, i don't know how to deal with this.
is there any way to throw exception if the app which i am launching is not installed on phone ?
or i should try something else so my task gets accomplished and app gets certified for store as well.
You do not need to wrap your launch in try/catch or check for success as described in the other answers. As soon as you call LaunchUriAsync, the platform takes over and will automatically handle the possibility of no app being installed by asking the user if she wishes to search in the store.
A couple of things to double-check:
1) Ensure that you can successfully back into your app following the navigation to sixtag.
2) Ensure that your call to LaunchUriAsync is the direct result of a user action (eg. tapping a button)
try
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
}
catch
{
MessageBox.Show("please install Sixtag from the app store","AppMissing", MessageBoxButton.OK);
}
you can perhaps display another button and on clicking directly navigate to the app store. See if this solves your problem. Do vote it up if it does :)
You are needed to handle that as shown here . Also Read out Remarks given there.

Which function does OpenAs_RunDLL finally calls under Windows 8?

I'm trying to use OpenAs_RunDLLW to let the user select application he wants to open specific file with. But I don't want to really launch anything, just to let the user select and remember his choise so I can then open the file with this program later. In Windows XP, Vista and 7 OpenAs_RunDLLW finally used to call ShellExecuteExW, so I could temporary put the int 3 opcode at the beginning of this function, catch the exception and get all parameters passed to ShellExecuteExW. This was good and really worked.
But under Windows 8/8.1 it seems that OpenAs_RunDLLW does not call ShellExecuteExW, since the breakpoint is never hit. The selected app is launched instead. So, my question is - which API function does OpenAs_RunDLLW finally call to execute the program under Windows 8?
I believe that the shell now uses IAssocHandler::Invoke to open the item. However, you probably don't really care about that; what you want is a way to find out how to get the invocation handler.
For that, you want ShAssocEnumHandlers, which takes a file name extension and returns an association enumerator (that is, a function that will enumerate all the various applications that can open that extension).
On Windows Vista and later, use SHOpenWithDialog() instead of calling OpenAs_RunDLL(), and then use SHAssocEnumHandlers() to find out which handlers are registered and to invoke a particular handler when needed, instead of using ShellExecute().

WindowsPhone 8 (A jump to another application

WindowsPhone 8 (A jump to another application
)
I want to in my applications to invoke other applications, the application I don't know any news, just know the name, how do I use
. Await the Windows System. The Launcher. LaunchUriAsync (new Uri (" wechat: "));
"Wechat" should be placed here called program I want to use
First you have to write the following protocol in the WMAppManifest.xml under the Extensions tag. Thereafter you can launch your app from any other apps with the specified protocol name using Launcher.LaunchUriAsync method.
<Protocol Name="webchat" NavUriFragment="LaunchUri=%s" TaskID="_Default"/>
For further clarification you can refer the below link.
http://msdn.microsoft.com/en-in/library/windowsphone/develop/jj206987(v=vs.105).aspx

Using App.Current.Terminate() method in Windows phone 8

As windows phone 8 provides us with this method for programmatically terminate an app, will there be any issue while app submission if we use this in app for terminating a page while there is no backentry in the navigation history?
There won't be any issue in certification when using this call, but make sure you have saved all data in your app when calling this, because this call effectively kills your app immediately - ApplicationClosing even handler won't be raised after it!
Why would you call Application.Terminate when navigating back with an empty back stack? Just let the app close itself. Seems a bit pointless to me to overuse Application.Terminate().
I can't say much about the new Terminate method, but I do have an app (NOTE: Not a game) that does the following at certain points
private void Kill()
{
new Microsoft.Xna.Framework.Game().Exit();
}
This app passed certification without any problems. This was an app for both WP7 and WP8 so I did not have the ability to use Terminate().