android - How to update the location data in a single row in the server(without getting the data duplicated)? -
whenever new location data getting saved in new row instead of existing row getting updated new data. how can achieve it? below code:
parseobject customerrequest = new parseobject("customerrequest"); parsegeopoint parsegeopoint = new parsegeopoint(mcurrentlocation.getlatitude(), mcurrentlocation.getlongitude()); parsequery<parseobject> query = parsequery.getquery("parsegeopoint"); customerrequest.put("location", parsegeopoint); customerrequest.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { log.i("parse result", "successful!"); } } );
in above code, directly put data using .put without removing existing data using .remove w.r.t. below line:
customerrequest.put("location", parsegeopoint);
so, should add line customerrequest.remove("location");
before line customerrequest.put("location", parsegeopoint);
in code. so, code like:
parseobject customerrequest = new parseobject("customerrequest"); parsegeopoint parsegeopoint = new parsegeopoint(mcurrentlocation.getlatitude(), mcurrentlocation.getlongitude()); parsequery<parseobject> query = parsequery.getquery("parsegeopoint"); customerrequest.remove("location"); customerrequest.put("location", parsegeopoint); customerrequest.saveinbackground(new savecallback() { @override public void done(parseexception e) { if (e == null) { log.i("parse result", "successful!"); } } );
and on server side, make sure don't use add command save data. should use addorupdate or addorreplace or saveorupdate command depending upon db use.
Comments
Post a Comment