Mansinh
Mansinh

Reputation: 1435

wp8:Handle Toast notification when application is in backgroung

While my app is running I can receive toast notification,on ShellToastNotificationReceived(object sender, NotificationEventArgs e) event handler as keys in e.Collection.

If my app is not running and a toast notification arrives, a toast is displayed but how i can i handle this notification?

I mean which event is fire when my application is not running and notification arrives.

I know background agent but its not fulfill my requirement

Thanks.

Upvotes: 1

Views: 2154

Answers (2)

Suresh
Suresh

Reputation: 47

yes we can handle the toast notification. once the user clicks on toast notification we can send a request to our web service and do our job.

what happens when an user clicks on toast notification is it will redirect to the application launching event in App.Xaml.cs page. in that event depending upon the toast content you can proceed to the next step.

hope this helps.

still if you didn't get it done, just drop a mail to me

happy coding.

Upvotes: 1

Pavel Saniuk
Pavel Saniuk

Reputation: 788

Windows Phone platform is responsible to handle Push Notifications and developers don't have a direct access for notification handling when an app is not running. That means you can't do any background logic after Toast is received. But when Toast message contains <wp:Param> value with an Uri to a specific app page then user will be redirected to this page, if user taps a Toast popup. So, you can do specific job after user tapped a Toast popup. To accomplish it, you need add an parameter to Uri, for example /YourPage?IsToast=true and override OnNavigatedTo method of the page to run your business logic:

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.ContainsKey("IsToast"))
            {
                //do your business here
            }
    }

For other cases you need to use a background worker.

Upvotes: 2

Related Questions