0
String address = 0123456789;

Cursor unreadcountcursor = getContentResolver().query(Uri.parse("content://sms/inbox"),
new String[]{}, "read = 0 and address='"+address+"'", null, null);

int count = unreadcountcursor.getCount();

Isn't there a faster way of getting it? Because this code is very heavy to execute when you have to take the count for many numbers, it takes a lot of time to load. Is there another way, supposing that this code will be in a while loop. I know that using this in the adapter is faster and possible, but the problem with the adapter is that I have to scroll trough the list and return for the count to get updated and notifyDataSetChanged() doesn't do anything for this.

What would be the best solution?

Thanks.

Samet
  • 917
  • 12
  • 26

1 Answers1

1

I am not sure this will spare much of device time, but of yours - definitly:

 Cursor countCursor = getContentResolver().query(CONTENT_URI,
                "count(*) AS count",
                null,
                null,
                null);

        countCursor.moveToFirst();
        int count = countCursor.getInt(0);

cited from here

Community
  • 1
  • 1
Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • No, the question sounded interesting, I was sure that there could be a query with counting and I really found it on the net. That's all. – Gangnus Jan 13 '12 at 15:57