2

I'm trying delete duplicate installation when reinstall on android. I'm doing get query from ParseInstallation but it is not working.

I attach my code below:

public boolean checkDuplicate(String id, ParseInstallation installation){




    ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
    query.whereEqualTo("userId", id);
    query.findInBackground(new FindCallback<ParseInstallation>() {
        public void done(List<ParseInstallation> list, ParseException e) {
            if (e == null) {

                //Log.d("LISTA-CHECKDUPLICATE", "id " + list.size() );
                for(int i = 0; i<list.size(); i++){
                    try {
                        list.get(i).delete();
                    } catch (ParseException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }

            } else {
                Log.d("LISTA-CHECKDUPLICATE", "Error: " + e.getMessage());
            }
        }
    });


    return false;

}
gogoru
  • 376
  • 2
  • 19

1 Answers1

2

Finally I solved this with cloud code and calling this function on android:

Parse.Cloud.define("checkDuplicado", function(request, response) {
    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.Installation);
    var objectId = request.params.objectId;
    query.equalTo("userId", request.params.userId);
    query.first().then(function(duplicate) {
        if (typeof duplicate === "undefined" ) {
            console.log("Duplicate does not exist,New installation");
            response.success("Nueva Instalacion");
        } else if(duplicate.id != objectId){
            console.log("Duplicado existe..Intentando borrar " + duplicate.id );
            //console.log("userId-NUEVO " + request.object.get("userId") + " ID: " + request.object.id);
           // console.log("userId-DUPLICADO " + duplicate.get("userId") + " ID: "+ duplicate.id);
            duplicate.destroy().then(function(duplicate) {
                console.log("Duplicado borrado correctamente");
                response.success("Duplicado borrado correctamente");
            }, function() {
                console.log(error.code + " " + error.message);
                response.success("Error Borrando duplicado");
            });

           response.success("Check duplicados realizado correctamente");
        }
        else{
            response.success("Check duplicados realizado correctamente");
        }
    }, function(error) {
        console.warn(error.code + error.message);
        response.success("Error");
    });
    });
gogoru
  • 376
  • 2
  • 19
  • Hwy, after using this, I was able to delete the installation. But with it, My channel list has gone. How to copy Channel list to new installation before deleting old one? – Palak Darji Apr 01 '15 at 16:45
  • This means you can only have one user per device right? – clauziere Aug 26 '15 at 18:39
  • yes I have only user per device. and Palak Darji you can copy the channel before delete, read the row and copy the value. – gogoru Dec 12 '15 at 16:10