Thursday, 10 July 2014

android : Loading data from XML to SQLite take very long time



I have very large table 300,000 records I am loading from XML file to SQLite,


unfortunately, this is taking very very long time (took 15 min then I had to stop it).


is this normal?


is there anything wrong with my code.


how to speed it up?


thanks



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_filter);

new Thread(new Runnable() {
public void run() {
FillLocations();
}
}).start();

}




private void FillLocations()
{
OpenDB();
Resources res = getResources();
ContentValues _Values = new ContentValues();

//Open xml file
XmlResourceParser _xml = res.getXml(R.xml.locations);
try
{
//Check for end of document
int eventType = _xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
//Search for record tags
if ((eventType == XmlPullParser.START_TAG) &&(_xml.getName().equals("Cities"))){
//Record tag found, now get values and insert record
String City = _xml.getAttributeValue(null, "City");
String Country = _xml.getAttributeValue(null, "Country");
String Time = _xml.getAttributeValue(null, "Time");
_Values.put("City", City);
_Values.put("Country", Country );
_Values.put("Time", Time);
db.insert("Locations", null, _Values);
}
eventType = _xml.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

No comments:

Post a Comment