Backend DataStore Parse - sahajss/knowledge_base GitHub Wiki

As my project relies on user to user interaction, I found it pivotal to find a backend service that was both easy to navigate and efficient. With Parse, I found just that. _Parse _is currently owned by Facebook, and as such allows simple social media login (Twitter included), alongside user account creation. In addition, Parse offers cloud code capabilities (javascript), through which more complex algorithms and functions can be created and deployed, freeing up space on local storage. Furthermore, from push notifications to file storage, Parse has cross-platform SDKs, allowing users to sign in on an android device and then log in to a website whilst maintaining the same account information.

Setting Up User Accounts

On Android, signing up a User is relatively simple:

ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("[email protected]");
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
    }
  }
});

Parse WorkSpace

With a User account, managing data stored becomes a lot simpler as it can be tied to a unique user in the form of a Map. For instance, if you wanted to update the title attribute of a user, you could do:

ParseUser.getCurrentUser().put("title","Mobile Developer");
ParseUser.getCurrentUser().saveInBackground();

This would then send the information to Parse where it would be updated and displayed (for example), as shown in the following image:

Querying

When working with multiple users, I have found it is important to understand how to query all user data, and pick out specific information. For instance, if I wanted to gather a list of all people with a specific title stored in the cloud, I could conduct the following query in the cloud code:

  Parse.Cloud.define("findTitle", function(request, response) {
  var query = new Parse.Query(Parse.User);
  query.equalTo("title", "Mobile Developer"); //Once again, the parameters we pass are in Map(key, value) format.
  query.find({
    success: function(results) {
      response.success(results); /*Saves as ArrayList<ParseUser> in Java*/
    }
  })
});

Then, I can call this function in my own application, and in Java this would be:

   HashMap<String,Object> params = new HashMap<String,Object>();
   ParseCloud.callFunctionInBackground("findTitle", params, new FunctionCallback<ArrayList<ParseUser>>() {
   @Override
       public void done(ArrayList<ParseUser> parseUsers, ParseException e) {
          //Do Something with the ArrayList :D   
            }
        });

Overall, Parse allows for a high level control over one's application. Although the service is retiring in January 2017, Facebook has already allowed people to migrate their servers elsewhere, free of charge, as well as making Parse open-source. Throughout my own application I have used Parse to not only store user accounts, but also to: store locations and interests amongst other data, authenticate email sign-ups, and query data both locally and using the Parse Cloud functionality. An area I have yet to explore is push notifications, however I feel as though this would be tremendously helpful for any developer wanting to send data efficiently and quickly.

⚠️ **GitHub.com Fallback** ⚠️