@Override
 public void deleteTrack(long trackId) {
   Track track = getTrack(trackId);
   if (track != null) {
     String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?";
     String[] selectionArgs =
         new String[] {Long.toString(track.getStartId()), Long.toString(track.getStopId())};
     contentResolver.delete(TrackPointsColumns.CONTENT_URI, where, selectionArgs);
   }
   contentResolver.delete(
       WaypointsColumns.CONTENT_URI,
       WaypointsColumns.TRACKID + "=?",
       new String[] {Long.toString(trackId)});
   // Delete tracks last since it triggers a database vaccum call
   contentResolver.delete(
       TracksColumns.CONTENT_URI, TracksColumns._ID + "=?", new String[] {Long.toString(trackId)});
 }
  private ContentValues createContentValues(Track track) {
    ContentValues values = new ContentValues();
    TripStatistics tripStatistics = track.getTripStatistics();

    // Value < 0 indicates no id is available
    if (track.getId() >= 0) {
      values.put(TracksColumns._ID, track.getId());
    }
    values.put(TracksColumns.NAME, track.getName());
    values.put(TracksColumns.DESCRIPTION, track.getDescription());
    values.put(TracksColumns.CATEGORY, track.getCategory());
    values.put(TracksColumns.STARTID, track.getStartId());
    values.put(TracksColumns.STOPID, track.getStopId());
    values.put(TracksColumns.STARTTIME, tripStatistics.getStartTime());
    values.put(TracksColumns.STOPTIME, tripStatistics.getStopTime());
    values.put(TracksColumns.NUMPOINTS, track.getNumberOfPoints());
    values.put(TracksColumns.TOTALDISTANCE, tripStatistics.getTotalDistance());
    values.put(TracksColumns.TOTALTIME, tripStatistics.getTotalTime());
    values.put(TracksColumns.MOVINGTIME, tripStatistics.getMovingTime());
    values.put(TracksColumns.MINLAT, tripStatistics.getBottom());
    values.put(TracksColumns.MAXLAT, tripStatistics.getTop());
    values.put(TracksColumns.MINLON, tripStatistics.getLeft());
    values.put(TracksColumns.MAXLON, tripStatistics.getRight());
    values.put(TracksColumns.AVGSPEED, tripStatistics.getAverageSpeed());
    values.put(TracksColumns.AVGMOVINGSPEED, tripStatistics.getAverageMovingSpeed());
    values.put(TracksColumns.MAXSPEED, tripStatistics.getMaxSpeed());
    values.put(TracksColumns.MINELEVATION, tripStatistics.getMinElevation());
    values.put(TracksColumns.MAXELEVATION, tripStatistics.getMaxElevation());
    values.put(TracksColumns.ELEVATIONGAIN, tripStatistics.getTotalElevationGain());
    values.put(TracksColumns.MINGRADE, tripStatistics.getMinGrade());
    values.put(TracksColumns.MAXGRADE, tripStatistics.getMaxGrade());
    values.put(TracksColumns.MAPID, track.getMapId());
    values.put(TracksColumns.TABLEID, track.getTableId());
    values.put(TracksColumns.ICON, track.getIcon());
    return values;
  }