Specify max sqlite db size for my app. How to handle db full exception
Although there is no limit on the size of the database except for available storage, you can set the maximum size the database will grow to by SQLiteDatabase.setMaximumSize()
. If you reach the limit you have to shrink your database. Or you can move your database from internal memory to external storage possibly with more free space available and increase database maximum size. But heavy databases lead to bad user experience so second option consider theoretic. Remember we are in mobile environment not in a dedicated database server.
First, to set the maximum database size use .setMaximumSize()
as mentioned in the previous answer.
Second, Android throws SQLiteFullException
if the database file grows larger than maximum number of pages * page size. SQLiteFullException
is a RuntimeException
. If you want to handle it and send a relevant response you will do something like:
try {
getContentResolver().update(myEntity.CONTENT_URI, values, where, null);
} catch (SQLiteFullException e) {
Log.w(TAG, "Exception when updating ...", e);
}