I was asked in an interview how can we set max size for sqlite db for our android app. And how can we handle when max size is reached?
EDIT: Marina Lynn’s answer below seems acceptable to this question. But Are there some sort of listeners which are triggered when the db size reaches near the limit we have specified? (Or something like this)
First, to set the maximum database size use
.setMaximumSize()as mentioned in the previous answer.Second, Android throws
SQLiteFullExceptionif the database file grows larger than maximum number of pages * page size.SQLiteFullExceptionis aRuntimeException. If you want to handle it and send a relevant response you will do something like: