ANDROID: Finding the size of individual tables in a SqliteDatabase
If you mostly store binary or string data in a single column, you can use an aggregate query:
SELECT SUM(LENGTH(the_column)) FROM the_table
This can give you a reasonable estimate even when the size of each row varies a lot (for example if you store pictures in the database). However, if you have many columns with a small amount of data in each, your approach (estimating a fixed size per row) is better.
On Android, you can implement it like the following:
SQLiteDatabase database = ... // your database// you can cache the statement below if you're using it multiple timesSQLiteStatement byteStatement = database.compileStatement("SELECT SUM(LENGTH(the_column)) FROM the_table");long bytes = byteStatement.simpleQueryForLong();