Download RSS Feed

Fox

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
      Dim parser As SaxParser
   Dim PhoneIntents1 As PhoneIntents
End Sub

Sub Globals
   Dim btnDownload As Button
   Dim ListView1 As ListView
   Dim Title, Link, pubDate As String
   Dim in As InputStream
End Sub

Sub Activity_Create(FirstTime As Boolean)
   parser.Initialize
   If FirstTime Then
   DownloadService.URL = "http://www.url.de/rss/rss.xml"
   DownloadService.Target = File.OpenOutput(File.DirInternalCache, "rss.xml", False)
   StartService(DownloadService)
   End If
   'check if we already loaded the image previously.
End Sub

Sub Activity_Resume
   'check if download has finished while the activity was paused
   If DownloadService.JobStatus = DownloadService.STATUS_DONE Then
      FinishDownload
   End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)

End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
   If parser.Parents.IndexOf("item") > -1 Then
      If Name = "title" Then
         Title = Text.ToString
      Else If Name = "link" Then
         Link = Text.ToString
      Else If Name = "pubDate" Then
         pubDate = Text.ToString
      End If
   End If
   If Name = "item" Then
      ListView1.AddSingleLine2(Title, Link) 'add the title as the text and the link as the value
   End If
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
   StartActivity(PhoneIntents1.OpenBrowser(Value)) 'open the brower with the link
End Sub

Sub FinishDownload
   If DownloadService.DoneSuccessfully = True Then
   ListView1.Initialize("ListView1")
   Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
   ListView1.SingleLineLayout.ItemHeight = 80dip
   'parse the xml file
   in = File.OpenInput(File.DirInternalCache, "rss.xml")
   parser.Parse(in, "Parser")  <<< here get an error
   in.Close
   End If
   DownloadService.JobStatus = DownloadService.STATUS_NONE
   
End Sub

Why my program quits on the line : parser.Parse(in, "Parser")

what is wrong on this?
 

alfcen

Well-Known Member
Licensed User
Longtime User
Perhaps it might be easier to assist if you posted the Service module as well.
 
Upvote 0
Top