android - Parse.com saveAllInBackground doesn't work inside deleteAllInBackground -
i trying save list of parseobjects using save in background. avoid duplices in table, querying existing rows , deleting them if , save new copy.
the parseobject.saveallinbackground gets execued, callbacks getting called, no rows getting saved.
i sure list passing saveallinbackground has parseobjects.
i debugged methods, flow runs intended.
update 1:
when number of rows delete less number of rows added, newer rows persisted. meaning, rows not present in list passed deleteallinbackground method persisted.
this code
parsequery query = new parsequery("postchoice"); query.frompin(); query.findinbackground(new findcallback<parseobject>() { @override public void done(final list<parseobject> locallist, parseexception e) { if (locallist != null && !locallist.isempty()) { list<parseobject> postlist = new arraylist<parseobject>(); (parseobject object : locallist) { postlist.add(object.getparseobject("post")); } parsequery query = new parsequery("postchoice"); query.wherecontainedin("post", postlist); query.whereequalto("user", parseuser.getcurrentuser()); query.findinbackground(new findcallback<parseobject>() { @override public void done(list<parseobject> parsecloudlist, parseexception e) { if (parsecloudlist != null && !parsecloudlist.isempty()) { parseobject.deleteallinbackground(parsecloudlist, new deletecallback() { @override public void done(parseexception e) { // gets executed , rows accordingly deleted parseobject.saveallinbackground(locallist, new savecallback() { @override public void done(parseexception e) { // gets executed rows not uploaded. //the locallist not empty. contains right data. editor.putlong(four.last_choice_sync_time, system.currenttimemillis()); editor.commit(); log.i("syncchoiceservice", "synced choices"); } }); } }); } else{ parseobject.saveallinbackground(locallist, new savecallback() { //this method works fine , uploads. issue arises when saveallinbackground called inside deleteallinbackground's call @override public void done(parseexception e) { log.i("syncchoiceservice", "synced choices"); editor.putlong(four.last_choice_sync_time,system.currenttimemillis()); editor.commit(); } }); } } }); } } });
query.frompin();
- might using local datastore, not sureparseobject.saveallinbackground(locallist...
make sure locallist not empty. have suspicion when call save method.first 2 queries dublicate themselves, make query instead of two:
parsequery query = new parsequery("postchoice"); query.whereequalto("user",parseuser.getcurrentuser());
- im not sure, there might limit nesting bacground callbacks. might try call method in activity class 1 of callbacks, continues chain.
Comments
Post a Comment