Parse.com

As we all experienced on our last assignment, working with backends for mobile applications is both a blessing and a curse. It is a blessing in the sense that we are able to store and access large amounts of data for our applications, but most backend database APIs are poorly documented, if at all, and sometimes hard to work with.  In the last couple of weeks we were introduced to MobDB as well as MongoDB.  These are currently two of the most widely used backends for android applications.  However they are not the only choice, there are a myriad of choices out there for android backend databases.   Parse.com is a widely used, well documented alternative to MobDB or MongoDB, that is also free to try.

Parse.com is very similar to MobDB in the sense that it can use any type that can be JSON-encoded.  Parse.com uses it’s own type called ParseObject to interact with the backend, much the same way that MobDB uses InsertRowData or GetRowData objects.  The syntax for insert and delete however is a little easier and less frustrating using Parse.com.  A simple insert can be seen here:

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

With this example, you can see that there are similarities with MobDB.  However you do not need to create a  listener class for callback. Also, Parse.com automatically  creates an id which is a unique identifier for each object saved to the backend.  There are also some similarities to MobDB when retrieving data from Parse.com.  An example can be seen here:

ParseQuery query = new ParseQuery("GameScore");
query.whereEqualTo("playerName", "Dan Stemkoski");

query.findInBackground(new FindCallback() {
        public void done(List<ParseObject> scoreList, ParseException e) {
            if (e == null) {
                Log.d("score", "Retrieved " + scoreList.size() + " scores");
            } else {
                Log.d("score", "Error: " + e.getMessage());
            }
        }
    });

As you can see, we had to define our callback’s done method. This callback method is much shorter and less complicated than the MobDB callback methods which returned JSONObjects and made you sift through the object to find the element that you need.  You can see that our score will be in the List of ParseObjects called scoreList.   Now that we have our object we can extract the data very easily using the provided methods getInt(“key”), getString(“key”), getBoolean(“key”), etc.  Parse.com also has methods to store and retrieve files as byte arrays, much the same way that MobDB stores and retrieves files.  Pasre.com also has an API for storing, querying, and retrieving geopoints, which is something new that I have not seen with other backend services.

Parse.com seems to offer the same services of MobDB or MongoDB for free, so some of you may want to try it out for future projects or applications.  Some useful links:

Parse.com Android API

Parse.com Android Guide

Parse.com Docs