public void addGBActivitySample(ActivitySample sample) { try (SQLiteDatabase db = this.getWritableDatabase()) { ContentValues values = new ContentValues(); values.put(KEY_TIMESTAMP, sample.getTimestamp()); values.put(KEY_PROVIDER, sample.getProvider().getID()); values.put(KEY_INTENSITY, sample.getRawIntensity()); values.put(KEY_STEPS, sample.getSteps()); values.put(KEY_TYPE, sample.getRawKind()); db.insert(TABLE_GBACTIVITYSAMPLES, null, values); } }
@Override public void addGBActivitySamples(ActivitySample[] activitySamples) { try (SQLiteDatabase db = this.getWritableDatabase()) { String sql = "INSERT INTO " + TABLE_GBACTIVITYSAMPLES + " (" + KEY_TIMESTAMP + "," + KEY_PROVIDER + "," + KEY_INTENSITY + "," + KEY_STEPS + "," + KEY_TYPE + ")" + " VALUES (?,?,?,?,?);"; SQLiteStatement statement = db.compileStatement(sql); db.beginTransaction(); for (ActivitySample activitySample : activitySamples) { statement.clearBindings(); statement.bindLong(1, activitySample.getTimestamp()); statement.bindLong(2, activitySample.getProvider().getID()); statement.bindLong(3, activitySample.getRawIntensity()); statement.bindLong(4, activitySample.getSteps()); statement.bindLong(5, activitySample.getRawKind()); statement.execute(); } db.setTransactionSuccessful(); db.endTransaction(); } }