title: insertWithOnConflict() vs. Insert or replace
body: <p>I was refactoring my code and replacing all <code>insert</code> statements with <code>insert or replace</code>while i found the following method that uses <code>db.insert()</code> instead of a prepared statement:</p>
  
  <pre><code>public static void insertIntoTableByNameAndFieldsAndValues(
          String tableName, String[] fields, String[] values, Context c)
          throws FieldsAndValuesMismatchException, UnrecognizedTypeException   {
  
      DatabaseAbstractionLayer dal = new DatabaseAbstractionLayer(c);
      SQLiteDatabase db = dal.getWritableDatabase();
  
      ContentValues con = new ContentValues();
  
      if (fields.length != values.length)
          throw new FieldsAndValuesMismatchException(
                  "fieldsString and values are not the same size");
  
      int fieldCount = fields.length;
  
      for (int i = 0; i &lt; fieldCount; i++) {
          String[] fieldArr = fields[i].split(":");
          String value = values[i];
          if (fieldArr[1].equalsIgnoreCase("long")) {
              // long
              if(value.equalsIgnoreCase("null")){
                  con.putNull(fieldArr[0]);
              }else{
                  con.put(fieldArr[0],(long) Integer.parseInt(value));
              }
          } else if (fieldArr[1].equalsIgnoreCase("string") || fieldArr[1].equalsIgnoreCase("text")) {
              // string
  
              if(value.equalsIgnoreCase("null")){
                  con.putNull(fieldArr[0]);
              }else{
                  con.put(fieldArr[0], value);
              }
  
  
          }else if(fieldArr[1].equalsIgnoreCase("double")){
              //double
  
              if(value.equalsIgnoreCase("null")){
                  con.putNull(fieldArr[0]);
              }else{
                  con.put(fieldArr[0], Double.valueOf(value));
              }
  
          } else {
              throw new UnrecognizedTypeException(fieldArr[1]
                      + " is not string,text, long or double");
          }
      }
  
      db.insert(tableName, null, con);
  
   db.close();
  }
  </code></pre>
  
  <p>I don't want to rewrite the code and use a raw query. 
  Is there a way to replace a row when a conflict occurs? I guess <code>insertWithOnConflict()</code> would do that but I couldn't find a good example. </p>