XmlPullParser in a Thread returns nothing every other run. Why?
<p>I have a simple <code>XmlPullParser</code> in a non-UI thread that parses some data from an XML over HTTP and stores it in a local MySQL database. The first time around, the parsing operation goes beautifully and all the data ends up where it should. But without fail, if I start the parse operation again (assuming the activity hasn't been destroyed and recreated in the meantime), it returns nothing. It doesn't throw up any exceptions; rather it acts as if it's already at the end of the file and simply finishes without finding any tags. Then if I run it a third time, it works fine again, and the cycle repeats.</p>

<p>Is there a method I should be calling to properly close the parser when it's finished? I looked around in the docs and examples but couldn't find anything about it.</p>

<p>Here's a cut-down version of the relevant code:</p>

<pre><code>parseThread = new Thread () {                
    public void run() {

        mDB.delete(directoryPeople.TEMP_TABLE, null, null);

        XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
        XmlPullParser parser = parserCreator.newPullParser();

        URL feed = new URL(directoryUrl);
        parser.setInput(feed.openStream(), null);

        ContentValues entry = new ContentValues();
        int parserEvent = parser.getEventType();
        String tag = "";
        String value = "";
        entryCount = 0;

        while (parserEvent != XmlPullParser.END_DOCUMENT) {

            if(parserEvent == XmlPullParser.START_TAG) {
                tag = parser.getName();
                if (isPeopleField(tag)) {
                    parserEvent = parser.next();
                    value =  parser.getText();
                    entry.put(tag, value.replaceAll("\n", ""));
                }
            }
            if(parserEvent == XmlPullParser.END_TAG &amp;&amp; parser.getName().compareTo("ROW") == 0) {
                mDB.insert(directoryPeople.TEMP_TABLE, null, entry);
                entryCount++;
                hUpdateProgressBar.sendEmptyMessage(0);
                entry.clear();
            }
             parserEvent = parser.next();
        }

        /** Copy temp table to permanent table */
        mDB.delete(directoryPeople.PEOPLE_TABLE, null, null);

        String copyQuery = "INSERT INTO " + directoryPeople.PEOPLE_TABLE
            + " SELECT * FROM " + directoryPeople.TEMP_TABLE;

        mDB.execSQL(copyQuery);

        /** Delete contents of temp table */
        mDB.delete(directoryPeople.TEMP_TABLE, null, null);

        mHandler.post(new Runnable() {
        public void run() {
                adapter.getCursor().requery();
                }
        });
    }
};
parseThread.start();
</code></pre>
