Code Snippet – How to get the count of rows from SQLite Database In Android?

Android comes with a utility class called DatabaseUtils which has a method queryNumEntries that can take your database object and table name as parameter and return the total number of records on that database. Quite a clean way. You don’t need to be writing ‘Select Count(*) from mytable‘ kind of stuffs.

public long count() {
    return DatabaseUtils.queryNumEntries(db,'myTablename');
}