I have the following code, which checks for the number of rows in the database.
private void checkMMSRows(){
Cursor curPdu = getContentResolver().query(Uri.parse("content://mms/part"), null, null, null, null);
if (curPdu.moveToNext()){
int number = curPdu.getCount();
System.out.println(number);
}
}
I will to run this code every second and do something when the value has changed. The problems is, how do I go about “detecting” the change? Any help would be appreciated.
Very basically, add a class variable – you can either make it
staticacross all instances of the class, or an instance variable (by removing thestatickeyword).Each time you get a number, you can compare it to
oldNumber. After the comparison, set theoldNumberto the current number – so you have something to compare against next time:Update:
My answer’s a straight code hack & slash solution, but I’d probably recommend amit’s answer.