简体   繁体   中英

Saving data and reading data from Parse.com local datastore on android

On android, I'm saving a Username to Parse local datastore

Parse.enableLocalDatastore(this);

Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

ParseObject UserObject = new ParseObject("UsernameClass");

UserObject.put("username", username);    

UserObject.pinInBackground();

And to get the saved data I'm using this -

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("UsernameClass");

        query.orderByAscending("_created_at");
        try {
            ob = query.find();
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }


        for (ParseObject Userr : ob) {
            Srting user = Userr.get("username");
        }

The app is getting crashed and force closed on running. Is the code I'm using wrong somewhere ?

to get the saved data add .fromLocalDatastore(); to query.

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("UsernameClass"); 
query.fromLocalDatastore();

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM