2

I have to try download Data into an ArrayList . When i call it inside done() method it's ok, but when i call it outside done() it's will be null. How i can fix it?

        ParseQuery<ParseObject> query = ParseQuery.getQuery("code");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> provineList, ParseException e) {
            if (e == null) {
                for (ParseObject mProvine : provineList) {
                    Provine provine = new Provine();
                    provine.setPro((String) mProvine.get("provine"));
                    provine.setNumber((String) mProvine.get("code_number"));
                    provines.add(provine);
                    Log.d("All provine", provines.get(i).getPro()); (it's ok, no problem).
                    i++;
                }
            } else
                Log.d("Provines", "Error: " + e.getMessage());
            }
        }
    });
Log.d("All provine", provines.get(0).getPro()); (it's null ).

1 Answer 1

1

You can declare a subclass which extends ParseObject.

Call ParseObject.registerSubclass(YourClass.class) in your Application constructor before calling Parse.initialize().

Follow this Subclasses https://www.parse.com/docs/android/guide#objects-subclassing-parseobject

      // Armor.java
    import com.parse.ParseObject;
    import com.parse.ParseClassName;

    @ParseClassName("Armor")
    public class Armor extends ParseObject {
    }

    // App.java
    import com.parse.Parse;
    import android.app.Application;

    public class App extends Application {
      @Override
      public void onCreate() {
        super.onCreate();

        ParseObject.registerSubclass(Armor.class);
        Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
      }
    }

On Query you get that data as ArrayList.

ParseQuery<Armor> query = ParseQuery.getQuery(Armor.class);
query.whereLessThanOrEqualTo("rupees", ParseUser.getCurrentUser().get("rupees"));
query.findInBackground(new FindCallback<Armor>() {
  @Override
  public void done(List<Armor> results, ParseException e) {

    // here you can use results same as object model.


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

Comments

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.