I am trying minimize memory usage. My application get slower when the this code running and memory increase 50-100mb
public void setAllSeriestoDatabase(String jsonString){
try {
removeSQL();
SQLiteDatabase db = getWritableDatabase();
JSONArray json = new JSONObject(jsonString).getJSONArray("musics");
String sql = "INSERT INTO musics (uid, title, genre, artist, count, image, adddate) VALUES (?,?,?,?,?,?,?,?,?,?,?);";
SQLiteStatement statement = db.compileStatement(sql);
db.beginTransaction();
for (int i = 0; i < json.length(); i++) {
statement.clearBindings();
statement.bindString(1, json.getJSONObject(i).getString("id").toString());
statement.bindString(2, json.getJSONObject(i).getString("name").toString());
statement.bindString(3, json.getJSONObject(i).getString("genre").toString());
statement.bindString(4, json.getJSONObject(i).getString("artist").toString());
statement.bindString(5, json.getJSONObject(i).getString("count").toString());
statement.bindString(6, json.getJSONObject(i).getString("coverimg").toString());
statement.bindString(7, json.getJSONObject(i).getString("adddate").toString() );
statement.execute();
}
statement.close();
db.setTransactionSuccessful();
db.endTransaction();
db.close();
} catch (JSONException e) {}
}
Aucun commentaire:
Enregistrer un commentaire