Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created October 21, 2011 17:03
Show Gist options
  • Select an option

  • Save developernotes/1304329 to your computer and use it in GitHub Desktop.

Select an option

Save developernotes/1304329 to your computer and use it in GitHub Desktop.
public class CrossProcessCursorWrapper extends CursorWrapper implements CrossProcessCursor {
public CrossProcessCursorWrapper(Cursor cursor) {
super(cursor);
}
@Override
public CursorWindow getWindow() {
return null;
}
@Override
public void fillWindow(int position, CursorWindow window) {
if (position < 0 || position > getCount()) {
return;
}
window.acquireReference();
try {
moveToPosition(position - 1);
window.clear();
window.setStartPosition(position);
int columnNum = getColumnCount();
window.setNumColumns(columnNum);
while (moveToNext() && window.allocRow()) {
for (int i = 0; i < columnNum; i++) {
String field = getString(i);
if (field != null) {
if (!window.putString(field, getPosition(), i)) {
window.freeLastRow();
break;
}
} else {
if (!window.putNull(getPosition(), i)) {
window.freeLastRow();
break;
}
}
}
}
} catch (IllegalStateException e) {
// simply ignore it
} finally {
window.releaseReference();
}
}
@Override
public boolean onMove(int oldPosition, int newPosition) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment