Monday, January 23, 2012

WP7 ShellTileSchedule, Secondary Tiles Update Problem

Already in one of my last posts I blogged about the ShellTileSchedule class. I love the simplicity of this class and still use it in my Shortcuts App you can get here. After a complete re-design of the App, I did a lot of testing and found an interesting bug.

My App did not refresh webcam images on phone, sms and mail live tiles.

I know the limitations of the ShellTileSchedule class and checked them again and again.

Limitation
Note that you can only provide a RemoteImageUri. Therefore you must provide an online and available URI that represents an image to download and display. You can’t reference URI from your local application. The image size can NOT exceed 80KB, and download time can NOT exceed 60 sec.

The bug must be somewhere else. Half a night later I found the problem in the link property of the tile to update. If the link has more than one parameter (like my phone, sms and mail tiles),  the update will not work. If there is non or only one parameter (like all my other functions) it works. So I changed the signature of the links and now everything is fine.

Old code
         var tile = new StandardTileData()
         {
           Title = "Demo"
         };
         var link = new Uri
           (string.Format(
             "/Phone.xaml?name={0}&number={1}", 
             nameTextBlock.Text, 
             numberTextBlock.Text)
             , UriKind.Relative);
         ShellTile.Create(link, tile);  

New code
         var tile = new StandardTileData()
         {
           Title = "Demo"
         };
         var link = new Uri
           (string.Format(
             "/Phone.xaml?name={0}%{1}", 
             nameTextBlock.Text, 
             numberTextBlock.Text)
             , UriKind.Relative);
         ShellTile.Create(link, tile);  

On the target form I changed the way to read the parameter to this
       if (this.NavigationContext.QueryString.Keys.Contains(Constants.NAME))
         _name = this.NavigationContext.QueryString[Constants.NAME];
       var x = _name.Split(new Char[] { '%' });
       _name = x[0];
       _number = x[1];  

3 comments:

Andreas Hammar said...

Nice tip! Thanks for posting

Peter said...

Yes, I've run into the same problem with my live tiles. I gave up on using a query string entirely and updated all my routes in mvc.

Peter said...
This comment has been removed by the author.