Array operations sometimes throws 'Operation is invalid after previous operation'

android, parse-platform

Solution

In the Parse documentation under arrays it says

"Note that it is not currently possible to atomically add and remove items from an array in the same save. You will have to call save in between every different kind of array operation."

When you both add and remove from your parse object, it will throw the error "Operation is invalid after previous operation". To avoid this error first add the new values to the array, save the object, remove the old values, then save again.

Problem

In one of my parse subclasses I have a method like this: ``` public void updateCheckpoint(String checkpoint, boolean checked) { if (checked) { addUnique(checkedCheckpoints, checkpoint); } else { removeAll(checkedCheckpoints, Arrays.asList(checkpoint)); } } ``` This update is immediately followed by a pinning to the local datastore. Even when adding a ProgressDialog to ensure that the pinning has completed between updates, then sometimes the `Operation is invalid after previous operation` is thrown. Is there a more robust way of doing array operations?

Original source