in database.
public int getCnt() {
String countQuery = "SELECT * FROM " + TABLE_LOG;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null)
int cnt = cursor.getCount();
cursor.close();
return cnt;
}
also tried
public long getCnt() {
SQLiteDatabase db = this.getReadableDatabase();
long cnt = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM " + TABLE_LOG, null);
return cnt;
}
in main
int x =0; // long for other func..
x = dbh.getCnt();
Toast.makeText(getApplicationContext(),String.valueOf(x),Toast.LENGTH_SHORT).show();
if(x==0){
//do some stuff
}
else{
//do some other stuff
}
it works but only when the table has 0 rows, when it encounter any row i dont know what went wrong but app stops ,, and please let me know if any other info is required