1
votes

I'm trying to send a toast notification with a parameter to a Windows Phone 8.1 device, so when a user taps on the toast the app will show a particular page within the app, as it described in this MSDN article https://msdn.microsoft.com/library/windows/apps/jj662938(v=vs.105).aspx

This is a snippet that I use to add a parameter:

<wp:Param>?cmd=command1 </wp:Param>

this how I read it in the app:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
            base.OnNavigatedTo(e);
            string strVal1 = this.NavigationContext.QueryString["cmd"];
        }

After making these changes it works correctly, but only for this first notification. In all subsequent notifications the value of the parameter read within the app is same as it was in the first notification, no matter what I've sent from the server.

Here is an example:

  1. I'm sending a notification to device that has with this parameter in the notification payload: <wp:Param>?cmd=command1 </wp:Param> The value in this.NavigationContext.QueryString("cmd") is command1, as it should be.
  2. Then I send a second notification with this parameter parameter <wp:Param>?cmd=command2 </wp:Param> the cmd's value in the this.NavigationContext.QueryString("cmd") is still returned as "command1" instead of command2 as it should be. And it works like that for all subsequent notifications until I force-restart the app.

Here is what I've tried:

  1. Checked the Uri value in the NavigationEventArgs argument of the OnNavigatedTo event and it's same as what I see in the NavigationContext.
  2. Double checked notification payload sent from the server (it's correct)
  3. Checked msdn/stackoverflow/google.
  4. Checked on both 8.1 emulator and the device (it works the same)

Questions:

  1. Do I have to do something in the app (idk, clear NavigationContext or something), so it will be different for the next notification?
  2. Does anyone actually has a live-app that uses partial arguments (not server-driven navigation with full url, but a partial url passed to the app + corresponding navigation from within the app) and it works for multiple subsequent notifications?
1

1 Answers

1
votes

Figured out what the problem was. Two OnNavigated events are fired when app is relaunched. First one has a type of System.Windows.Navigation.NavigationMode.Reset and it has the data of the old page being reset (in my case, with the data from old notification). The second one is System.Windows.Navigation.NavigationMode.New and has the data from the new notification.

A simple check of navigation mode to make sure it's of the type .New fixed the issue:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
        base.OnNavigatedTo(e);
    if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)){
    // custom navigation logic based on the data within <wp:Param/>
    }
}