UWP C# - 从通知点击重新启动应用程序 [英] UWP C# - Re-launch app from notification click

查看:33
本文介绍了UWP C# - 从通知点击重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 UWP 应用程序,我有一个 ScheduledToastNotification,当应用程序暂停时(例如,像提醒一样)添加到日程表中.但是,如果我关闭应用程序,通知会准时出现,但是当我点击通知(没有按钮,一般只是在通知上)时,应用程序无法正确启动,停在初始屏幕上.

I'm writing a UWP app, and I have a ScheduledToastNotification that is added to the schedule when the app is suspended (e.g. like a reminder). However, if I close the app, the notification appears on time, but when I click on the notification (no buttons, just on the notification in general), the app doesn't launch correctly, stopping at the splash screen.

如何让应用正确重新启动?

How do I get the app the re-launch correctly?

谢谢.

推荐答案

你应该覆盖 App.Xaml.cs 中的 OnActivated 并像这样处理

You should override OnActivated in App.Xaml.cs and handle this like

protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.ToastNotification)
            {
                var toastArgs = args as ToastNotificationActivatedEventArgs;
                var arguments = toastArgs.Argument;

                if (arguments == "ARG")
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    if (rootFrame == null)
                    {
                        rootFrame = new Frame();
                        Window.Current.Content = rootFrame;
                    }
                    rootFrame.Navigate(typeof(YOURPAGE));
                    Window.Current.Activate();
                }
            }
        }

这篇关于UWP C# - 从通知点击重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆