My application receives some data from server in XML form. I parse it using XmlPullParser. Everything works fine. Until server sends large nested object – bitmap or file in BASE64 encoding (up to 10+Mb). On old devices with little VM heap (2.3 for example) application crashes on String text = parser.getText(); (out of memory)
What should I do in this case?
Is there any way to get stream? Or mabey XmlPullParser can split it and give it to me by parts?
One possiblility is to swich to Sax Parsing. The main difference being that it will not need to read the entire xml string into memory at once. Instead it will work its way through it in small chunks.
It is a bit more complex to set up, but if you search around online for things like “Android Sax Parsers example” there are some good samples to get you started. It is really not any more difficult just takes a moment to get accustomed to doing it that way instead of with a pull parser.