page_type | urlFragment | languages | products | description | |||
---|---|---|---|---|---|---|---|
sample |
foregroundapp-backgroundapp |
|
|
An example of building a foreground app and background app within the same APPX file for Windows 10 IoT Core. |
These are the available versions of this Windows 10 IoT Core sample.
In both versions, the Background App currently toggles a GPIO pin. If you are using a Dragonboard, you'll need to change LED_PIN in StartupTask.cpp (for C++) or StartupTask.cs (for C#) to a pin that exists on the Dragonboard (for example, the User LED 1: pin 21). You can find a list of available pins for the Dragonboard here.
If you want to create a solution that builds the foreground application and the background application into the same .APPX file it will require manual steps to combine the two projects.
- File>New>Project…
- Create a new Blank App
- Select desired target version and click OK when prompted for target version
- In Solution Explorer right-click on the solution and choose Add>New Project …
- Create a new Background Application
- Select desired target version and click OK when prompted for target version
- In Solution Explorer right-click on the background application Package.appxmanifest and choose View Code
- In Solution Explorer right-click on the foreground application Package.appxmanifest and choose View Code
-
At the top of the foreground Package.appxmanifest add xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" and modify IgnorableNamespaces to include iot.
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" IgnorableNamespaces="uap mp iot">
-
Copy the from the Background Application project Package.appxmanifest to the Foreground Application Package.appxmanifest. It should look like this:
<Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="MyForegroundApp.App"> <uap:VisualElements DisplayName="MyForegroundApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="MyForegroundApp" BackgroundColor="transparent"> <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/> <uap:SplashScreen Image="Assets\SplashScreen.png" /> </uap:VisualElements> <Extensions> <Extension Category="windows.backgroundTasks" EntryPoint="MyBackgroundApplication.StartupTask"> <BackgroundTasks> <iot:Task Type="startup" /> </BackgroundTasks> </Extension> </Extensions> </Application> </Applications>
-
In Solution Explorer right-click on the Foreground Application References node and choose Add Reference…
-
In Solution Explorer right-click the foreground application project and choose Unload Project, then right-click the background application project and choose Unload Project.
-
In Solution Explorer right-click on the foreground application project and choose Edit MyForegroundApp.csproj and then right-click on the background application project and choose Edit MyBackgroundApp.csproj.
-
In the background project file comment the following lines:
<!--<PackageCertificateKeyFile>MyBackgroundApplication_TemporaryKey.pfx</PackageCertificateKeyFile>--> <!--<AppxPackage>true</AppxPackage>--> <!--<ContainsStartupTask>true</ContainsStartupTask>-->
-
In the foreground project file add true</ ContainsStartupTask> to the first PropertyGroup
<PropertyGroup> <!-- snip --> <PackageCertificateKeyFile>MyForegroundApp_TemporaryKey.pfx</PackageCertificateKeyFile> <ContainsStartupTask>true</ContainsStartupTask> </PropertyGroup>
-
In Solution Explorer right-click on each project and choose Reload Project
- In Solution Explorer delete Package.appxmanifest from the background application
- At this point the project should build (and run the implementation you have added to the foreground and background applications).