These two days by the database into the batch data tortured a little crazy okay found a solution, not much to say, directly look at the following two parts of the code:
Sqlitedatabase db = Dbhelper.getwritabledatabase ();
LOGUTILS.I ("Start parsing *****************" + new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
for (int i = 0; i < messagearray.length (); i++) {
try {
Jsonobject Messageobject = (jsonobject) messagearray.get (i);
int stamp = Jsonutils.getint (Messageobject, "Ntime", 0);
String Dblon = jsonutils.getstring (Messageobject, "Dblon", "");
String Dblat = jsonutils.getstring (Messageobject, "Dblat", "");
/******************** Database Transactions Start **************************/
Db.begintransaction ();
Db.execsql ("INSERT into Waybaby (stamp,lontude,lantude) VALUES (?,?,?)", new object[] {stamp, dblon,dblat});
Db.settransactionsuccessful ();
Db.endtransaction ();
/******************** database Transaction End **************************/
Trancelist.add (Double.parsedouble (Dblat));
Trancelist.add (Double.parsedouble (Dblon));
LATLNG latlng = new Latlng (double.parsedouble (Dblat), double.parsedouble (Dblon));
Latlngline.add (LATLNG);
catch (Jsonexception e) {
E.printstacktrace ();
}
}
Dismissprogressdialog ();
LOGUTILS.I ("Parsing end *****************" + New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
Draw the trajectory of the course
Onmaploaded ();
This code is used to parse the data, and then insert into the local database, total: 1000 data, When: 10 seconds ~~15 seconds. 15 seconds of waiting, the flowers are all thanks. Take a look at the modified code below:
Sqlitedatabase db = Dbhelper.getwritabledatabase ();
LOGUTILS.I ("Start parsing *****************" + new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
for (int i = 0; i < messagearray.length (); i++) {
try {
Jsonobject Messageobject = (jsonobject) messagearray.get (i);
int stamp = Jsonutils.getint (Messageobject, "Ntime", 0);
String Dblon = jsonutils.getstring (Messageobject, "Dblon", "");
String Dblat = jsonutils.getstring (Messageobject, "Dblat", "");
Locusentity locusentity = new Locusentity (stamp, Dblon, Dblat);
Locusentities.add (locusentity);
Trancelist.add (Double.parsedouble (Dblat));
Trancelist.add (Double.parsedouble (Dblon));
LATLNG latlng = new Latlng (double.parsedouble (Dblat), double.parsedouble (Dblon));
Latlngline.add (LATLNG);
catch (Jsonexception e) {
E.printstacktrace ();
}
}
LOGUTILS.I ("Start inserting data *****************" + New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
Db.begintransaction ();
String sql = "INSERT into Waybaby (stamp,lontude,lantude) VALUES (?,?,?)";
for (locusentity locusentity:locusentities) {
Sqlitestatement stat = db.compilestatement (SQL);
Stat.bindlong (1, Locusentity.getstamp ());
Stat.bindstring (2, Locusentity.getlontude ());
Stat.bindstring (3, Locusentity.getlantude ());
Stat.executeinsert ();
}
Db.settransactionsuccessful ();
Db.endtransaction ();
Db.close ();
LOGUTILS.I ("Insert data complete *****************" + New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
Dismissprogressdialog ();
LOGUTILS.I ("Parsing end *****************" + New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (new Date ());
Draw the trajectory of the course
Onmaploaded ();
Careful of you, you will find that the operation of inserting data, was taken to the outside of the For loop, while the operation of inserting the database also changed, a large number of code, from a row into more than 10 lines, but the efficiency of the improvement is not a little two points. This code executes time: Less than 1 seconds, print time information, you will find that time does not take 1 seconds to obtain success. I've been printing for less than 1 seconds. Nearly 10 times times faster than before, you dare believe? This is the truth. As to what that piece of code means. Please own Baidu, learn by yourself.