0

I want to make the background agent in my Windows Phone app check for new feeds in the background, i use webclient to download them and i display them in an listbox i use an webbrowser control to display the selected feed to the page it comes from via url i got from the syndicationitem, now i want to save lets say the title or the publishdate to isolated storage and that the background agent checks every 30 min. for feeds and checks if some new feed are available with comparing the the last feed Title or the last publishdate saved already and the newsest on the page, then if a newer feed is there it should send an toast notification with the title of the feed and open my app.

i have nothing done to save the feeds before, i dont know how to do this and i dont know how to use background agents and do thid what i wrote above. I use Microsofts example of an rss reader as background for my app logic. downloading, displaying all that like the sample here - http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh487167(v=vs.105).aspx

here is some code:

i use this to download the feeds

WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new System.Uri("http://wpnovosti.com/feeds/posts/default?alt=rss"));

this i use to show them on my listbox and there is some logic of the live tiles too:

public void UpdateFeedList(string feedXML)
    {


        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);  

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            // Bind the list of SyndicationItems to our ListBox.
            feedListBox.ItemsSource = feed.Items;
            SystemTray.SetProgressIndicator(this, null);

            //Live Tiles
            ShellTile appTile = ShellTile.ActiveTiles.First();
            if (appTile != null)
            {
                FlipTileData TileData = new FlipTileData()
                {
                    Title = "",
                    BackTitle = "WP Novosti",
                    BackContent = feed.Items.First().Title.Text,
                    WideBackContent = feed.Items.First().Title.Text,
                    Count = 0,
                };

                appTile.Update(TileData);
            }
            else
            {
            }


        });

this i use if an item is selected on the listbox:

public void feedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListBox listBox = sender as ListBox;


        if (listBox != null && listBox.SelectedItem != null)
        {
            // Get the SyndicationItem that was tapped.
            SyndicationItem sItem = (SyndicationItem)listBox.SelectedItem;


            // Set up the page navigation only if a link actually exists in the feed item.
            if (sItem.Links.Count > 0)
            {                   
               Uri uri = sItem.Links.FirstOrDefault().Uri;

               NavigationService.Navigate(new Uri("/Pregled.xaml?url=" + uri, UriKind.Relative));

               UpdateFeedList(State["feed"] as string);
            }

        }
    }

the rest is just displaying this passed url on another page via webbrowser control. how can i make this really work now like i want described on top?!

dinchy87
  • 169
  • 1
  • 12
  • MSDN has [good example code for Background Agents](http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202941(v=vs.105).aspx), try this first. – Neil Turner Sep 29 '13 at 13:13
  • i have looked at this sample but i need more info about how to save the feeds first tile and so that the background agent can use it and compare if the last one that it downloads is newer and if it is then to send a toast notification... the problem is i am a newbie, i have this code on mainpage to download the feeds but how can i download them in backgroundagent, how to save the first title or publishdate... – dinchy87 Sep 29 '13 at 18:38
  • The simple approach to save you feed is serialize it. Background agent then can deserialize it and see latest update as you wish. Then you can either update your feed or send toast notification. If you update you feed in background context, make sure you manage synchronization between background & foreground app as described in MSDN. – Khoi Jun 27 '14 at 14:50

0 Answers0