UWP_Can not start app using StartupTask Class?

混江龙づ霸主 提交于 2019-12-11 02:26:17

问题


I follow this article to startup my UWP app when system reboot.

https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.startuptask#uwp-app-startup-task-extension

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.


回答1:


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();
}



回答2:


From official document, the UWP App startup task extension is

<Package xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" ...>
...
<Applications>
    <Application ...>
        ...
        <Extensions>
          <uap5:Extension Category="windows.startupTask">
            <uap5:StartupTask
              TaskId="MyStartupId"
              Enabled="false"
              DisplayName="Test startup" />
          </uap5:Extension>
      </Extensions>
    </Application>
</Applications>

You could copy to your app's Package.appxmanifest directly. And it works in my side. Note that when your app starts at startup, it will start minimized in the taskbar.

If you use startup task extension that in Configure your app to start at log-in blog, you need to modify Executable and EntryPoint property to be equal to Application's EntryPoint property. Note, avoid using $targetnametoken$.exe wildcards in Extension.

<Extensions>
  <uap5:Extension
    Category="windows.startupTask"
    Executable="StartUpTest.exe"
    EntryPoint="StartUpTest.App">
    <uap5:StartupTask
      TaskId="MyStartupId"
      Enabled="false"
      DisplayName="Test startup" />
  </uap5:Extension>
</Extensions>


来源:https://stackoverflow.com/questions/49531061/uwp-can-not-start-app-using-startuptask-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!