title: Parsing XML and getting different results when running debugger, vs. just running
body: <p>As part of a larger project, I'm using an XMLPullParser to read in the data from the BBC news rss feed. 
  When I hit run, I get a list of duplicates of the last item (title, description, pubDate, and link). 
  However, when I put a breakpoint on the line with the Log.i(), then my code works perfectly, and pulls each article with it's correct variables. Any idea why it would run differently with debug vs run?</p>
  
  <p>publishProgress(100) is what triggers the article to be added to a ListView in the actual app. 
  Here is the link to the rss feed that I'm parsing: <a href="http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml" rel="nofollow noreferrer">http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml</a></p>
  
  <pre><code>                try {
                      val url = URL(bbcUrl)
                      val urlConnection = url.openConnection() as HttpURLConnection
                      val inStream = urlConnection.inputStream
  
                      //Set up the XML parser:
                      val factory = XmlPullParserFactory.newInstance()
                      factory.isNamespaceAware = false
                      val xpp = factory.newPullParser()
                      xpp.setInput(inStream, "UTF-8")
  
  
                      var eventType: Int = xpp.eventType      //While not the end of the document:
                      while (eventType != XmlPullParser.END_DOCUMENT) {
                          eventType = xpp.eventType
                          when (eventType) {
                              XmlPullParser.START_TAG         //This is a start tag &lt; ... &gt;
                              -&gt; {
  
                                  if(xpp.name == "item")
                                      Log.i("newItem", "New Article Found") //Breakpoint goes here
  
                                  when (xpp.name) {
                                      "title" -&gt; {
                                          xpp.next()
                                          title = xpp.text
                                          publishProgress(25)
                                      }
                                      "description" -&gt; {
                                          xpp.next()
                                          description = xpp.text
                                          publishProgress(50)
                                      }
                                      "link" -&gt; {
                                          xpp.next()
                                          link = xpp.text
                                          publishProgress(75)
                                      }
                                      "pubDate" -&gt; {
                                          xpp.next()
                                          pubDate = xpp.text
                                          publishProgress(100)
                                      }
                                      null -&gt; {
  
                                      }
                                  }
                              }
                              XmlPullParser.END_TAG           //This is an end tag: &lt;/ ... &gt;
                              -&gt; {
                              }
                              XmlPullParser.TEXT              //This is text between tags &lt; ... &gt; Hello world &lt;/ ... &gt;
                              -&gt; {
                              }
                          }
                          xpp.next() // move the pointer to next XML element
                      }
                  }
                  catch(ex: MalformedURLException){
                      ret = "MalformedUrlException"
                  }
                  catch(ex : IOException ){
                      ret = "IO Exception"
                  }
                  catch(ex : XmlPullParserException){
                      ret = "XML Pull Exception. The XML is not properly formed"
                  }
  </code></pre>
  
  <p>Edit:
  Never solved the root of this problem, but adding a sleep(1) in my while loop beside my Log.i() caused the program to run as intended. Still looking for an answer, but this will work for now. </p>