It seems like everything is moving to the cloud these days. Microsoft Azure offers Mobile Services to handle authentication, notifications, storage, and many more services for your applications. One less thing to worry about since the cloud can handle login and storage for me. This speeds up development and time to market.
When I started writing android applications, I spend a lot of time finding tools and services to help me write these apps faster. That’s when I met Parse, a cloud-based platform that can handle login, storage, and push notifications.
Parse was acquired by Facebook in 2013 in a deal worth $85 million. Since the acquisition, Parse has open source their SDK. They currently have SDKs for iOs, Android, JavaScript, OS X, Unity, PHP, .Net, Xamarin, Arduino, and Embedded C.
Let’s take a look at the Anywall Android application to see how Parse handles our backend needs.
The Anywall Android app code is hosted at github and you can read the code with this link.
To keep things simple, I’m going to focus on the SignUpActivity.java file and see what it takes to register a new user with Parse.
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password);
// Call the Parse signup method
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
dialog.dismiss();
if (e != null) {
// Show the error message
Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
} else {
// Start an intent for the dispatch activity
Intent intent = new Intent(SignUpActivity.this, DispatchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
});
It is very simple. You first create a new instance of ParseUser and then call the signUpInBackground method. If we get an error message, we show the error message to the user. If the sign up process was successful, we send the user to the dispatch activity.
Very simple! I’m free to concentrate on my application code. For this example, I was not concern with the database setup and maintenance. And also the ParseUser handles all the authentication and user management for me. With all the time saved by not doing these things, I can focus on my application’s logic and user experience.
If you take a look at the Application.java file, you will see the setup needed by Parse to communicate with our app.
@Override
public void onCreate() {
super.onCreate();
ParseObject.registerSubclass(AnywallPost.class);
Parse.initialize(this, "YOUR_PARSE_APPLICATION_ID",
"YOUR_PARSE_CLIENT_KEY");
preferences = getSharedPreferences("com.parse.anywall", Context.MODE_PRIVATE);
configHelper = new ConfigHelper();
configHelper.fetchConfigIfNeeded();
}
The above code is calling the initialize method with our Parse application id and client key.
Now let’s create our own objects with Parse. Read the AnywallPost.java file.
package com.parse.anywall;
import com.parse.ParseClassName;
import com.parse.ParseGeoPoint;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
/**
* Data model for a post.
*/
@ParseClassName("Posts")
public class AnywallPost extends ParseObject {
// properties for this class
}
At the beginning of this file, we import Parse’s packages to help us create our own data models. And then just add the things you need. Pretty neat!
As you can see from these examples, Parse is handling my backed needs by providing services that handle user management, and storage. I can spend my time worrying about the application’s killer features. Give Parse a try and let me know how you like it.