I am creating an Android app that needs to access the Bible. I want it to be offline, so I prefer not to use one of the internet APIs. After reading this this post, I decided to store the text locally as XML, like this
<bible>
<b n="Genesis">
<c n="1">
<v n="1">In the beginning, God created the heavens and the earth.</v>
My problem is that the file is almost 34,000 lines long (4.4 MB) and it takes a LONG time (a few minutes) to parse the entire text.
Right now I'm using the XmlPullParser, like this
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
InputStream iStream = getResources().openRawResource(R.raw.bible);
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
xpp.setInput(reader);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
// do something here
eventType = xpp.next();
}
Is there a better way to store and/or access the bible locally on Android?
I've considered storing it as multiple XML files to parse it faster (a separate file for each book) but would prefer not to if possible.
I am open to any suggestions, including storing the text as something other than XML.
Thanks
- First of all Parse the XML
using SAX, DOM, or Pull Parser
, Or you can try some awesome Libraries like JAXP and JAXB or the infamous Castor
.
- Secondly you can store the Bible locally into SQLite
DataBase, As SQLite is merely a single file WITHOUT any Server, it works quite faster. It can be as small as 250K in size.
/////////////////// Edited Part ///////////////////////////////
- Its always better to keep the UI work on UI Thread, and Non-UI work on Non-UI thread, but that became a LAW with the arrival of HONEYCOMB
version of Android.
- So you can either use the Thread along with Handler
, or choose to use the easier option provided by Android know as PainLess Threading, its AsyncTask
- Using the above will keep your UI
responsive while you do the processor heavy work at the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With