Generic Content

The Song Translator app has both a square and a wide live tile to serve as the entrance to the home page and a way to entice users to re-enter the app. The live tile updates every 15 minutes with the help of a background task, which connects to Windows Azure to get the names of the three latest songs uploaded to the app by any user. These three songs are then displayed on the live tile, drawing users’ eyes to check if favorite songs have been recently uploaded.

Creating a Background Task

Step 1: First, the background task needs to be added to the Package.appxmanifest file. This requires adding “Background Tasks” under the drop-down menu for Available Declarations. The entry point of the background task was set to be the file that contains all of the code for the background task – in the case of Song Translator, a file called BackgroundTasker.BackgroundTask.

Step 2: The next step of setting up a background task is registering it. To do this, a new BackgroundTaskBuilder was created to register our background task. Then, key properties were set such as the name of the background task and the entry point. This is done as a precaution to as the entry point was already set in the Package.appxmanifest file. Then set the trigger time – to designate how often the background task runs. In Windows, background tasks cannot be triggered more frequently than every 15 minutes to conserve energy
and resources. For Song Transaltor, the trigger is set to 15 minutes. The actual registration of the background task will take place when the user runs the app for the first time.

Step 3: Finally, one important part of the background task is being able to unregister it. To do this, iterate through all of the existing tasks in Windows and deleted a task if its name corresponded with the name of our live tile background task. This was beneficial when first creating the background task where more frequent changes are likely to occur. A task cannot be registered if it already exists, so users will need to unregister the task every time before registering the task again.

Directing the Background

In this step users will be retrieving content from Azure to update the live tile. All of these processes were contained within one method, which was named UpdateTileData.

Step 1: First, retrieve a list of all of the uploaded items in our cloud storage.

Step 2: Create two tiles, a square tile and a wide tile (Windows 8 app live tiles come in two sizes that the user can choose between) and set the templates for each of the tile types. Windows has a list of premade tile templates that we were able to choose from.

Step 3: The tile templates chosen for Song Translator contained a logo image as well as several lines of text. While the logo image will fixed, the text will update every 15 minutes. As a result, after getting the list of latest songs from Azure, the app was set for first line item to be the list of songs to rotate first through live tile, the second line of text to be the second item in the list, and so on.

Running the Background Task

The final part of creating the background task is running it. For this purpose, Song Translator had a Run method that simply called the UpdateTileData method. However, since UpdateTileData was an asynchronous method, to prevent the Run method from completing and exiting before the background task finished a background task deferral was created to defer the Run method until the background task finished updating the live tile.

Song Translator Live Tiles


Learn More