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 callStats = ((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?