3
I was able to enter information in the database using the method getReadableDatabase()
. In that case shouldn’t it be wrong? Shouldn’t it be the method getWritableDatabase()
?
private void savePet() {
petDbHelper = new PetDbHelper(this);
db = petDbHelper.getReadableDatabase();
ContentValues values = new ContentValues();
values.put(PetEntry.COLUMN_PET_NAME, mNameEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_BREED, mBreedEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_WEIGHT, mWeightEditText.getText().toString());
values.put(PetEntry.COLUMN_PET_GENDER, mGender);
long newRowID =
db.insert(PetEntry.TABLE_NAME, null, values);
/** Display rowID after finish */
Toast.makeText(this, "New row added: " + newRowID, Toast.LENGTH_SHORT).show();
/** Close Activity */
finish();
}
Documentation - getReadableDatabase
– NoobSaibot
Both return the same object
– Valdeir Psr
@wmsouza in many cases, it is easy not to understand exactly what the documentation says.
– Nakamoto