Implementing Android Content provider Insert(), using notifyChange() -
sorry, i'm not @ english.
i'm learning developing android apps in udacity. implemented insert() in content provider, , wonder. in code, there 2 different uris, returnuri , uri(past uri passed parameter).
@override public uri insert(uri uri, contentvalues values) { final sqlitedatabase db = mopenhelper.getwritabledatabase(); final int match = surimatcher.match(uri); uri returnuri; switch (match) { case weather: { normalizedate(values); long _id = db.insert(weathercontract.weatherentry.table_name, null, values); if ( _id > 0 ) returnuri = weathercontract.weatherentry.buildweatheruri(_id); else throw new android.database.sqlexception("failed insert row " + uri); break; } default: throw new unsupportedoperationexception("unknown uri: " + uri); } getcontext().getcontentresolver().notifychange(uri, null); return returnuri; }
please pay attention bottom of code. in lecture, have use past uri in getcontext().getcontentresolver().notifychange(), not returnuri. 'note must use past in uri, , not return uri, not correctly notify our cursors of change.' don't understand this. used returnuri instead of past uri. passed test, , worked! have use past uri?
Comments
Post a Comment