XMLPullParser on Android 2.x

This evening, working on my app, I noticed that the following way to instantiate a pull parser object works quite well on Jelly bean and newer android releases.

XmlPullParser xpp = Xml.newPullParser();

but it doesn’t work correctly on older Android versions.

Unfortunately calling the above method doesn’t throw any exception. The instantiated object just doesn’t work as it should.
For instance, getInputEncoding() returns null and some other methods just throw random exceptions.

My advise is to use the pull parser factory in order to instantiate a parser.
This works on the latest android version too.. so this is the right way to go:

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();