These are working notes the BAAS platform Parse. This is going to be a new chapter in our upcoming book. We are also developing a few apps with Parse as the backend. It has been a wonderful experience so far.

parse.com homepage

download the sdk

What are application Id and client key?

Search for: What are application Id and client key?


public void onCreate() { 
    Parse.initialize(this, appIdString, clientKeyString); 
}

Parse Android Guide


//a set of key value pairs
//Exammple

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();

objectId
createdAt
udpatedAt

ObjectId separates one parse object from the other


Be aware two objects of same type could have different key/value pairs
A programmer may want to use java types to deal with this well.

ParseQuery query = new ParseQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

Notice how you need an object id to retrieve it in this case. I suppose there will be query clauses just like SQL to retrieve sets of these objects satisfying a criteria.


myObject.refreshInBackground(new RefreshCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // Success!
    } else {
      // Failure!
    }
  }
})

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveEventually();

A final save will happen when the connection is up.


int myNumber = 42;
String myString = "the number is " + myNumber;
Date myDate = new Date();
 
JSONArray myArray = new JSONArray();
myArray.put(myString);
myArray.put(myNumber);
 
JSONObject myObject = new JSONObject();
myObject.put("number", myNumber);
myObject.put("string", myString);
 
byte[] myData = { 4, 8, 16, 32 };
 
ParseObject bigObject = new ParseObject("BigObject");
bigObject.put("myNumber", myNumber);
bigObject.put("myString", myString);
bigObject.put("myDate", myDate);
bigObject.put("myData", myData);
bigObject.put("myArray", myArray);
bigObject.put("myObject", myObject);
bigObject.put("myNull", JSONObject.NULL);
bigObject.saveInBackground();

On a single object type
or, and, on multiple attributes
nested queries like in clause
join like
data caching
compound queries

File uploads with progress indicator is possible


ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("[email protected]");
 
// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");

signup
login
verify emails
persistent logged in user/current user/session
Annonymous users that can join later
facebook user integration
twitter user integration
automatic annonymous users
user object seem to have security features

automatic user
user ACLs

ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
  // do stuff with the user
} else {
  // show the signup or login screen
}

You can find this docs at


//This will automatically create an annonymous user
//The data associated to this user is abandoned when it is 
//logged out.

ParseUser.enableAutomaticUser();

You can reset password through emails. Here is a link to the doc


ParseUser.logout()

ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("[email protected]");
 
// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");
 
user.signUpInBackground(new SignUpCallback() {
  public void done(ParseException e) {
    if (e == null) {
      // Hooray! Let them use the app now.
    } else {
      // Sign up didn't succeed. Look at the ParseException
      // to figure out what went wrong
    }
  }
});

Here is the guide for signup

Use this article to use progress dialogs to track asyncs

Use this article to handle forms better

How do I implement cursor behavior with ParseQuery?

Search for: How do I implement cursor behavior with ParseQuery?

Here is the parse forum

is there a record of who created a ParseObject

is there a record of who created a ParseObject?

Search for: is there a record of who created a ParseObject?

Here is something called parsefacade

This might throw some light on some that has used parse for a while and what insights there might be....

Yes and No. Parse only returns collections of one object type. That is the No part. However, if that object contains pointers to other objects it can return those (apparently) internal objects populated as well. (essentially kind of a join)

See this discussion link at Parse.com to support this idea

Here is what the parse docs says about this

In some situations, you want to return multiple types of related objects in one query. You can do this with the include method. For example, let's say you are retrieving the last ten comments, and you want to retrieve their related posts at the same time:


ParseQuery query = new ParseQuery("Comment");
 
// Retrieve the most recent ones
query.orderByDescending("createdAt");
 
// Only retrieve the last ten
query.setLimit(10);
 
// Include the post data with each comment
query.include("post");
 
query.findInBackground(new FindCallback() {
  public void done(List<ParseObject> commentList, ParseException e) {
    // commentList now contains the last ten comments, and the "post"
    // field has been populated. For example:
    for (ParseObject comment : commentList) {
      // This does not require a network access.
      ParseObject post = comment.getParseObject("post");
      Log.d("post", "retrieved a related post");
    }
  }
});

Is there a way to put unique constraints in Parse?

Search for: Is there a way to put unique constraints in Parse?

The include is documented here


ParseQuery query = new ParseQuery(WordMeaning.t_tablename);
query.whereEqualTo(WordMeaning.f_word, word);
query.orderByDescending(WordMeaning.f_createdAt);
       
//Include who created me
query.include(WordMeaning.f_createdBy);
       
//Include who the parent word is
query.include(WordMeaning.f_word);
       
//How can I include the owner of the word
query.include(WordMeaning.f_word + "." + Word.f_createdBy);

I am not sure if I need to do both


include("parent1)
include("parent1.parent2");

or just the later would do

Can I tell parse to always include a child object?

Search for: Can I tell parse to always include a child object?

Can I create a parse object from a parse Id on the client side?

Search for: Can I create a parse object from a parse Id on the client side?

Can I use put method to place arbitrary objects including date using parseobject.put method?

Values may be numerical, String, JSONObject, JSONArray, JSONObject.NULL, or other ParseObjects. value may not be null.

Here are my list of questions on parse at parse.com help section

How can I create a shell of a parse object if I know its id

is there a way to know what are the list of keys in a parseobject?

Search for: is there a way to know what are the list of keys in a parseobject?

Does anyone have an implementation of a Parcelable for a ParseObject?

Search for: Does anyone have an implementation of a Parcelable for a ParseObject?

Here is some discussion on this topic

Not yet!

is there a way to get the key collection of a ParseObject?

Search for: is there a way to get the key collection of a ParseObject?

They are not, by their sdk, parcelable or serializable. I have tried to write code to parcel them and they are not very cooperative. I was able to do this partially to get by.

But the fact appears to be a ParseObject may be doing more as part of its construction and behavior attached to it. If this were true we may be better of copying these objects where needed into pure Java Data Objects.

If you were to instead use a parse object underneath and do a look up based on reflection, we may not be able to overcome the need to searialize.

However we have to remember broadly that the power of no-sql is flexibility as well and not locked into a type. so what ever models we use they have to be hybrid. For instance you may want a parse object that can generate java objects of multiple types. or a single parse object behaving with multiple types. Like "TypeFaces!!" (A word I used to use when I want to cast a class to multiple types!)


query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK);
//milliseconds
query.setMaxCacheAge(100000L);

This query also sets the cache policy as above. This query did not put any where constraints.

This screen uses a particular approach for sending a parse object as a parcelable through an intent extra. The information you see about a word whose meaning we are trying to create is gotten through the intent extra!

This screen uses an intent extra to get the word parse object extra and also uses that parceled parse object word as a target to the where clause of the meanings query.

Note that when I say I am transfering the parse object as a parcelable, that is not entirely true as I am using a parse object wrapper to do the trick and works reasonably well. I have to admit i have to write a page or two of code to make this work. Hopefully I will document that some other day!

Do I need to change parse keys if I change may android package name?

Search for: Do I need to change parse keys if I change may android package name?

I have just changed my package name in my development environment. I didn't have to change my keys nor the application registration on parse.com. All the data is as before. So this is good. You can do this if you need to. Use the link above to see if there more nuances that I am not aware of at this early stage of a game!