0

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.

2
  • please paste your code here. Commented Sep 24, 2014 at 12:12
  • i just edited my post Commented Sep 24, 2014 at 12:29

1 Answer 1

2

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);

Sign up to request clarification or add additional context in comments.

3 Comments

well, i got your point but i have to store array of Strings like ["Basketball","Cricket","Hockey"], because i need to sort/search this string, for this reason i need to use login_data.addAllUnique(key,value);
you can put array of string in put method. if you want to sort/search then you should use another method to sort/search.
thank you @rajat i tried this and it all working fine. thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.