开发者

Android ContentResolver: Pass the data with cursor without requery or get the exact executed cursor when querying from activity

Say, I'm having a ContentProvider (which in fact do not performs database call) and I want to pass some additional data (for example, call statistics) with the cursor to the caller:

public class SomeProvider extends ContentProvider {

    . . .      

    public Cursor query(....) {
        // I can not set extras for cursor here
        return new MyCursorImplementation(iterationData, callStats);
    }

}

In activity, I want to make:

Cursor cursor = getContentResolver().query(...);
CallStats callStats = ((MyCursorImplementation)cursor).getCallStats();

But I can't make this because cursor is already wrapped in ContentResolver.CursorWrapperInner and ClassCastException is thrown.

It'd be very handy when using AsyncTask:

protected class SomeAsyncTask extends AsyncTask<Uri, Void, Cursor> {


     ...


     @Override
     protected Cursor doInBackground(Uri... uris) {
         return getContentResolver().query(uris[0], ...);
     }

     @Override
     protected void onPostExecute(Cursor cursor) {
         if (cursor != null) {
             // update view with cursor data, do other things using cursor

             CallStats call开发者_运维问答Stats = ((MyCursorImplementation)cursor).getCallStats();
             // do some UI changes using call statistics
             // ...but fails here
         } 
     }

}

How can I pass the data with the cursor or get exactly the same cursor that I've returned from query. Or it is impossible?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜