2

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

https://learn.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
enter image description here enter image description here Anyone has same problem? I really need some help. Thanks.

neo
  • 618
  • 1
  • 10
  • 29

2 Answers2

3

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();
}
Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
  • You are right, I missed that. What a silly, I only looked at the source code. The source code does not have OnActivate() too. Thanks. – neo Apr 17 '18 at 01:24
1

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>
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • I updated my question with pictures. I tried exactly source code in https://blogs.windows.com/buildingapps/2017/08/01/configure-app-start-log/#RIwvSuh80fSmHUWy.97 but the result is same. I don't know why because everything is seem right. The app is registered in Startup list and when I log-in the app startup and start minimized in task bar. Please give some help, thanks – neo Apr 16 '18 at 02:23
  • I have created same test app refer the blog, it works in my side, you could try to deploy your app in another machine to verify if your operation system fault. – Nico Zhu Apr 16 '18 at 02:28
  • I deployed the app in PC and tablet Panasonic FZ-M1 Windows 10 Pro, version 10.0.16299 N/A Build 16299, x64-based. Results are same.Could you share yours. – neo Apr 16 '18 at 03:24
  • 1
    Now I see what the problem is. I didn't implement OnActivate(), @Stefan Wick help me figure this out in below comment. I only looked at the sample code in the article and it doesn't have OnActivate() too. Anyway thanks a lot. – neo Apr 17 '18 at 01:29