Samet
Samet

Reputation: 917

A faster way of getting unread SMS count?

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.

Upvotes: 0

Views: 832

Answers (1)

Gangnus
Gangnus

Reputation: 24464

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

Upvotes: 1

Related Questions