UWP_无法使用 StartupTask 类启动应用程序? [英] UWP_Can not start app using StartupTask Class?
问题描述
我按照这篇文章在系统重启时启动我的 UWP 应用.
有人有同样的问题吗?我真的需要一些帮助.谢谢.
如果您的应用程序卡在启动时,这通常意味着您的代码没有调用 Window.Activate().
确保您为 ActivationKind.StartupTask 实现 OnActivate() 如下:
protected override void OnActivated(IActivatedEventArgs args){Frame rootFrame = Window.Current.Content as Frame;if (rootFrame == null){根框架 = 新框架();Window.Current.Content = rootFrame;}字符串有效载荷 = string.Empty;如果(args.Kind == ActivationKind.StartupTask){var startupArgs = args as StartupTaskActivatedEventArgs;有效载荷 = ActivationKind.StartupTask.ToString();}rootFrame.Navigate(typeof(MainPage), payload);Window.Current.Activate();}
I follow this article to startup my UWP app when system reboot.
UPDATE
I also tried that article, used exactly source code in that sample Configure your app to start at log-in
and below is phenomenon:
- when I click Request to Enable StartUp button on main page of UWP app, it shows Startup State as Enabled.
- I check Task manager, this app is enabled in startup list.
- After I restart PC and login, this app start and minimize to Taskbar immediately.
- When I click on the app icon on Taskbar, the app displays only splash screen.
- I leave the app that way for few minutes and it suddenly close without any notifications.
I can register my app to Startup list but after I login, my app does not auto start as my intention. It is always like following picture
Anyone has same problem? I really need some help. Thanks.
If your app is stuck at the splash this typically means that your code didn't call Window.Activate().
Make sure you implement OnActivate() for ActivationKind.StartupTask as follows:
protected override void OnActivated(IActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
string payload = string.Empty;
if (args.Kind == ActivationKind.StartupTask)
{
var startupArgs = args as StartupTaskActivatedEventArgs;
payload = ActivationKind.StartupTask.ToString();
}
rootFrame.Navigate(typeof(MainPage), payload);
Window.Current.Activate();
}
这篇关于UWP_无法使用 StartupTask 类启动应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!