I have a class on parse named as "UserData", containing a column name "usersports" which is an array type, I added the values successfully in that array, now I have to remove all the values, whenever I insert a new entry
login_data.addAllUnique("usersports",selected_sport_list);
where selected_sport_list
is my array list containing sports, and login_data
is the parse object
private class SaveUserDataToParse extends AsyncTask<String, String, String> {
private Context context;
private ProgressDialog progressDialog;
public SaveUserDataToParse(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
//Do your loading here
ParseQuery<ParseObject> query = ParseQuery.getQuery(Sportapp.USERDATA);
query.whereEqualTo(Sportapp.USER_GOOGLE_ID, google_id_from_preference.trim());
ParseObject login_data = query.getFirst();
if (login_data != null) {
login_data.put(Sportapp.USER_CITY, User_city);
login_data.put(Sportapp.USER_STATE, User_state);
login_data.put(Sportapp.USER_COUNTRY, User_country);
if(!selected_sport_list.isEmpty()){
login_data.addAllUnique(Sportapp.USER_SPORTS,selected_sport_list);
//login_data.removeAll(Sportapp.USER_SPORTS,selected_sport_list);
}
login_data.saveInBackground();
}
} catch (ParseException e) {
e.printStackTrace();
}
return "finish";
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Your Data has been successfully Saved", Toast.LENGTH_SHORT).show();
}
}
Since I got stuck, with the above code I am able to add data in parse array. But executing this code I have to remove the containing data of array on parse.
remove this line in your code :- login_data.addAllUnique(Sportapp.USER_SPORTS,selected_sport_list);
and add this :- login_data.put(Sportapp.USER_SPORTS,selected_sport_list);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.