java - Implementation of AbstractCursor for communication between Applications calls getString instead of getInt -
i'm writing simple "client/server" communication using content provider , custom cursor extending abstractcursor. provides simple key/pair sharing between 2 applications, each column being key , each value int (actually need booleans, map them 0's , 1's in int)
the client app opens contentproviderclient using content resolver, correctly reads column names, when calling getint values, on server app side see getstring being called instead of getint.
i can communicate values turning them strings, there way of forcing getint called directly, or must string conversion when communicating different apps?
here provider class code:
private static class stringbooleancursor extends abstractcursor { private final string[] keys; private final int[] values; public stringbooleancursor(map<string, boolean> data) { list<string> lkeys = new arraylist<string>(data.keyset()); keys = new string[lkeys.size()]; lkeys.toarray(keys); values = new int[keys.length]; (int = 0 ; < keys.length ; i++) { values[i] = data.get(keys[i]) ? 1 : 0; } } @override public int getcount() { return 1; } @override public string[] getcolumnnames() { return keys; } @override public string getstring(int column) { log.d(tag, "getstring " + column); return integer.tostring(values[column]); } @override public short getshort(int column) { log.d(tag, "getshort " + column); return 0; } @override public int getint(int column) { log.d(tag, "getint " + column + ": " + values[column]); return values[column]; } @override public long getlong(int column) { log.d(tag, "getlong " + column); return 0; } @override public float getfloat(int column) { log.d(tag, "getfloat " + column); return 0; } @override public double getdouble(int column) { log.d(tag, "getdouble " + column); return 0; } @override public boolean isnull(int column) { log.d(tag, "isnull " + column); return column < 0 || column >= keys.length; } } and relevant part of client:
cursor = cpc.query(configuri, null, null, null, null); if (cursor != null && cursor.movetonext()) { string[] keys = cursor.getcolumnnames(); (int = 0 ; < keys.length ; i++) { log.d(tag, "cursor.getint(" + + "): " + cursor.getint(i)); string key = keys[i]; boolean value = cursor.getint(i) != 0; log.d(tag, key + " <- " + value); } }
as selvin pointed out, have override gettype. default implementation in abstractcursor this:
public int gettype(int column) { // reflects assumption commonly used field types (meaning // blobs) convertible strings should safe call // getstring retrieve them. return field_type_string; } so overwriting (in case):
@override public int gettype(int column) { return field_type_integer; } now generates calls getlong(int) instead of getstring(int)
Comments
Post a Comment