Joshua
Joshua

Reputation: 59

Parse delete Object

I want to delete my data. I get "Student_ID" from my column consist of the ID at Parse. I am not sure where is the problem, the code had success one to two times when I tried, and with pressing the button multiple times. Maybe because it need to wait for the request from my database parse? I think the problem is at the for loop, it seem to stucks there. Can anyone fix it?

public void deleteStudent(){
    ParseQuery<ParseObject> query=ParseQuery.getQuery("Student");
    query.whereEqualTo("Student_ID",ID);
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> parseObjects, ParseException e) {
            if(e==null) {


                for (ParseObject delete : parseObjects) {
                    delete.deleteInBackground();
                    Toast.makeText(getApplicationContext(), "deleted", Toast.LENGTH_SHORT).show();
                }
            }else{
                Toast.makeText(getApplicationContext(), "error in deleting", Toast.LENGTH_SHORT).show();
            }
        }
    });
}

Upvotes: 1

Views: 2982

Answers (2)

Rene Xu
Rene Xu

Reputation: 1103

parse dose have an api to bulk delete, so save a for loop

ParseObject.deleteAllInBackground

Upvotes: 0

Joshua
Joshua

Reputation: 59

Just add this line to the void.

ID=student_ID.getText().toString();

Upvotes: 1

Related Questions