Update live tile count and add +1 to count every time the Live Tile is updated

381 views Asked by At

I have this little code here that is executed in my ScheduledTaskAgent of my Windows Phone app, if this code is executed then there is some data to show.

I have made an comparison before this code and I executes only if there is new data.

Now I have no clue how to add each time the live tile update +1 (one) int to the Count of the FlipTile I use. this is my code:

ShellTile appTile = ShellTile.ActiveTiles.First();
                        if (appTile != null)
                        {
                            FlipTileData TileData = new FlipTileData()
                            {
                                Title = "",
                                BackTitle = "my App",
                                BackContent = title.Collection.ElementAt(0).Title.ToString(),
                                WideBackContent = title.Collection.ElementAt(0).Title.ToString(),
                                Count =  ,     //?????
                            };


                            appTile.Update(TileData);

How can I make the count every time counts one more if this code is executed?

I have really no clue. I tried with +1 but its an int and it doesnt give this +1 to the next live tile update so the count should be 2.

I must say that ScheduledTaskAgent finishes its work and then a new instance of it is called, so I think the value that was first called in count must be saved, then at the next call retrieved and added to it +1. but how?

1

There are 1 answers

0
dinchy87 On

i found an easy sollution today that works. i made use of isolated storage to save the number of the count and give each time it updates +1 to it, then again save the new number (old+1) = new number and so on :) this is the code i use now. And it works perfectly in the ScheduledTaskAgent to update the Live Tile.

ShellTile appTile = ShellTile.ActiveTiles.First();
                        if (appTile != null)
                        {
                            if (IsolatedStorageSettings.ApplicationSettings.Contains("LiveTileCount"))
                            {
                                int count = (int)IsolatedStorageSettings.ApplicationSettings["LiveTileCount"];
                                FlipTileData TileData = new FlipTileData()
                                {
                                    Count = count +1,
                                };

                                IsolatedStorageSettings settings2 = IsolatedStorageSettings.ApplicationSettings;
                                if (!settings2.Contains("LiveTileCount"))
                                {
                                    settings2.Add("LiveTileCount", TileData.Count);
                                }
                                else
                                {
                                    settings2["LiveTileCount"] = TileData.Count;
                                };
                                settings2.Save();
                            }
                            else
                            {
                                FlipTileData TileData = new FlipTileData()
                                {
                                    Count = 1,
                                };

                                IsolatedStorageSettings settings2 = IsolatedStorageSettings.ApplicationSettings;
                                if (!settings2.Contains("LiveTileCount"))
                                {
                                    settings2.Add("LiveTileCount", TileData.Count);
                                }
                                else
                                {
                                    settings2["LiveTileCount"] = TileData.Count;
                                };
                                settings2.Save();
                            }
                        }
                        else
                        {
                            NotifyComplete();
                        }
                    }
                    else
                    {
                        NotifyComplete();
                    }