Cortana call causes crash on startup

I have a Windows Phone 8.1 Universal App in which I am working on adding basic Cortana support. Many articles about this for Silverlight, etc. “It's hard for me to find really good information about this.”

So far, I have activated the work if the application is already running or paused. However, if the application completely exited, then upon activation it will immediately work. I tried using hockey and the simple “LittleWatson” procedure to catch a crash, but it seems like it's too early to be caught. I saw some links to a private beta and trying to get a dump of crashes, but so far I have been unlucky.

Here my activation code looks like app.xaml.cs :

  protected override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); ReceivedSpeechRecognitionResult = null; if (args.Kind == ActivationKind.VoiceCommand) { var commandArgs = args as VoiceCommandActivatedEventArgs; if (commandArgs != null) { ReceivedSpeechRecognitionResult = commandArgs.Result; var rootFrame = Window.Current.Content as Frame; if (rootFrame != null) { rootFrame.Navigate(typeof(CheckCredentials), null); } } } } 

and here is my check for the result of the command:

  private async Task CheckForVoiceCommands() { await Task.Delay(1); // not sure why I need this var speechRecognitionResult = ((App)Application.Current).ReceivedSpeechRecognitionResult; if (speechRecognitionResult == null) { return; } var voiceCommandName = speechRecognitionResult.RulePath[0]; switch (voiceCommandName) { // omitted } ((App)Application.Current).ReceivedSpeechRecognitionResult = null; } 

I am sure that I am inserting messages, etc., that he fails long before he gets to this.

Most likely something light, but I don’t know what ...

What causes a disaster so early?

EDIT . One thing I tried is to use the "debug without launch" configuration to try to catch the exception. When I do this, the application seems to forever and forever connect in the debugger on the splash screen. However, this allowed me to take a break. He hangs in

 global::Windows.UI.Xaml.Application.Start((p) => new App()); 

which, as far as I can tell, just tells me that the application is hanging somewhere. This is the only line in the call stack.

+5
source share
1 answer

Copy the OnLaunched code segment into OnActivated, as in the example below. OnLaunched is not called when the application is activated, and it does some important work, such as activating a window.

 protected override void OnActivated(IActivatedEventArgs args) { // When a Voice Command activates the app, this method is going to // be called and OnLaunched is not. Because of that we need similar // code to the code we have in OnLaunched Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); rootFrame.CacheSize = 1; Window.Current.Content = rootFrame; rootFrame.Navigate(typeof(MainPage)); } Window.Current.Activate(); // For VoiceCommand activations, the activation Kind is ActivationKind.VoiceCommand if(args.Kind == ActivationKind.VoiceCommand) { // since we know this is the kind, a cast will work fine VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args; // The NavigationTarget retrieved here is the value of the Target attribute in the // Voice Command Definition xml Navigate node string target = vcArgs.Result.SemanticInterpretation.Properties["NavigationTarget"][0]; 
+10
source

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


All Articles