Quite some time ago I blogged about Live Tiles & Toast Notifications Windows 8 feature.
About a week ago I was delivering Windows 8 training and as a part of this course was delivering a sessions about Live Tiles and Windows 8 PLM (PLM = Process Lifetime Management, session which discusses when Windows 8 runs apps and some point about Windows 8 background tasks). The PLM session mentions, that Windows 8 apps are permitted to run background tasks, but they will be executed approximately once in 2 hour and will be getting few seconds of CPU time. I’ve also mentioned, that some apps, which got user permission to run under the lock screen will be able to run the background tasks based on system timer, but those apps will be scheduling to run once in 15 minutes as minimum timeslot between the execution. Right after the PLM session, at the break, one of my students came to me and asked how “clock” live tiles applications (already few published in the Store) are working. I had to admit, that I never saw this apps before and was not aware about them and how do they working. The student pointed out on one of them and after installing the app I saw that the app go a live tile with current clock and it updates the tile once in a minute. I have to admit, I was intrigued…
I checked the app permissions – it used background permissions, but this was not enough to update a tile once in a minute (remember – the minimum timeslot for such apps are 15 minutes). Then (after briefly chatting about this with my friend and colleague from MS DPE) I assumed that app probably uses push notifications. After further thoughts I failed also this option as the app is free and pushing 1440 messages daily per client is way above free limit of push notifications. I double checked myself by disconnecting network connections on my laptop to make sure. The app keep working and updated the tile. And suddenly it hit me – the app uses Scheduled Toast Notifications! It is possible to schedule many future toasts (I don’t remember exact number, but way more than 15 (needed for background service with lock screen permissions) and more than 120 (needed for regular background service). I tried to repro the app and here it is – for the sake of simplicity I didn’t create images of all minutes per day (actually half is enough as analogue clock has the same presentation once in 12 hours). Also I decided to make a sample without background service as for my demo it was not rally needed.
So I’ve create the super simple UI which gets a count number from user:
And here is button click event handler:
Note: In this sample I am using NotificationsExtensions – the free windows component created by Microsoft and distributed for free as a part of Windows 8 SDK samples.
That’s it! Wow! So simple, but super creative! The video of my sample running (sorry for ugly UI):
Clock app schedules the tiles using different tile template and points to images distributed with app. IMO it schedules 60-120 notifications, and every time background task runs adjust slightly the time and reschedules the tiles. I saw few times that the tile “skips” a minute sometime and jumps two minutes or stays on same minute instead of changing an image which makes me thing that at this time background task was running and adjusted an tiles schedule.
Enjoy and stay tuned!