Android Small Talks: Backendless – an Alternative to Parse.com

Android Small Talks: Backendless – an Alternative to Parse.com

Parse.com was one of the most popular MBaaS services (Mobile backend as a service). It facilitated creating a database in a cloud and made access to it available through an automatically generated API. Unfortunately, some time ago this project was announced to be closed, which forced us to find an alternative. From many websites of this sort, I have finally decided to choose Backendless.com.

Why do I choose Backendless as my MBaaS service?

Backendless provides us with a lot of functionalities, including:

  • User Management,
  • Data Persistenceter,
  • Geolocation,
  • Media Streaming,
  • Publish/Subscribe Messaging,
  • Push Notifications,
  • Custom Business Logic,
  • Analytics,
  • Mobile Code Generation.

To enable connecting to the database, SDK was made available for both Android and iOS. However this is not the only method of connecting – we can also do it through the REST API, so everyone can choose whatever is most convenient to them.

Below I will explain the basic functionalities, such as user management, communication with a database, and own business logic.

User management

Backendless has a special table for users. It is automatically created for each new application. SDK provides special methods and classes that allow you to register new users and execute the logging process in an easy way.

We also have at our disposal a dedicated system that facilitates confirming having created a new account by sending its user an e-mail with an activation link.

Registration

User registration is very simple. SDK is provided with the class BackendlessUser, which has fields such as e-mail and password. Moreover, we can add any field by setting property passing key and value.

All queries using SDK are held by calling static methods of respective classes. In this case, it is our UserService class. For each query performed in the background, we pass an appropriate callback, which is called with a response from API.

public void registerUser(String username, String email, String password) {
        BackendlessUser user = new BackendlessUser();
        user.setEmail(email);
        user.setPassword(password);
        user.setProperty("username", username);

        Backendless.UserService.register(user, new AsyncCallback<BackendlessUser>() {
            @Override
            public void handleResponse(BackendlessUser response) {
            }

            @Override
            public void handleFault(BackendlessFault fault) {
            }
        });
    }

Logging in

Logging users in is handled in a very similar way to registration. We also use the UserService class. For logging in, we need an e-mail address used for registration and a password.

public void loginUser(String username, String password, BaseDataCallback<UserProfile> callback) {
        Backendless.UserService.login(username, password, new AsyncCallback<BackendlessUser>() {
            @Override
            public void handleResponse(BackendlessUser response) {
            }

            @Override
            public void handleFault(BackendlessFault fault) {
            }
        });
    }

Communication with a database

Backendless allows us to automatically map database tables to our classes. If our class has a name different than a table we need to add a call for the mapping method (preferably in the application class). For example:

Backendless.Persistence.mapTableToClass("BackendlessProduct", Product.class);

Now we can save and write data while performing operations on our objects. Once again, we will use static methods.

Saving product

public void saveProduct(Product product, BaseDataCallback<Product> callback) {
        Backendless.Persistence.save(product, new AsyncCallback<Product>() {
            @Override
            public void handleResponse(Product response) {
            }

            @Override
            public void handleFault(BackendlessFault fault) {
            }
        });
    }

Getting the product list

public void getProducts(BaseDataCallback<ArrayList<Product>> callback) {

        Backendless.Persistence.of(Product.class).find(new AsyncCallback<BackendlessCollection<Product>>() {
            @Override
            public void handleResponse(BackendlessCollection<Product> response) {
            }

            @Override
            public void handleFault(BackendlessFault fault) {
            }
        });
    }

For all tables in the database which were created by us, we use the Persistence class. It provides us with the methods necessary for table content management, such as save, remove, find, loadRelations.

Business logic

If we need to perform any additional operations on the database, e.g. when saving objects, Backendless will be of great help. For such purposes, there was made available a special module allowing adding code that is to be executed before or after a particular action. The selection of actions is quite large and includes removing objects, saving, and searching. We can write code for business logic in Java, PHP, or JavaScript.

A simple example may look like this:

@Asset( "Product" )
public class ProductTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<Product> {

  @Override
  public void beforeCreate( RunnerContext context, Product product) throws Exception {
    product.setDescription("This is cloud code generated description");
  }   
}

It is enough to extend the class PersistenceExtender, and then overwrite appropriate methods. In this case, it is a beforeCreatemethod, which, as the name suggests, is called before saving an object to a database. These methods can be performed synchronously or asynchronously. The configuration for each class is available in the developer panel.

To sum up, Backendless is an excellent choice for those looking for an alternative to Parse.com or simply an MBaaS service. Its main advantages are providing access to a database both by using SDK and REST queries and an option of writing your own business logic.

Grzesiek

Grzesiek Lipski

Grzesiek has been specializing in professional Android app development for 9 years. He likes modern solutions and always pays attention to high-quality code. Grzesiek eagerly tests new possibilities, so he also builds apps with Flutter, and after hours he tries his hand at game development in Unity3D. When he’s not programming, he plays squash or takes photos with a drone.

Learn more

5 Reasons Why You Should Build the UI in ConstraintLayout

ConstraintLayout is a popular solution that Android developers use every day. And not without a good reason. If you’re at the beginning of your journey as a software engineer, get familiar with the most important features this layout can offer. It will help you understand the way it works, and Android app development will become easier.

Read more

How to Implement Feature Flags and Gain More Control over Your App?

Every person with software development experience can share a few stories about incorrectly working features. We build our apps out of small pieces, introduce advanced architecture patterns, and yet sometimes one of the elements fails, causing bugs or even system failures. In such cases, feature toggling can save the day! Find out how to implement feature flags, and make your app more stable.

Read more

How to Send iOS Notifications in Different Languages? Guide to Dynamic Localization

The best way to set a connection between a user, provider, and an app? System notifications. They allow users to get the latest news in no time. This solution is easy to implement in apps dedicated to one market. But it gets complicated when the messages must be displayed in many languages. In such cases, the dynamic localization of remote notifications can be a real game-changer.

Read more

Project estimation

Let us know what product you want to build and how we can help you.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2021

Winning app in
EVERYDAY LIFE category

Nagroda Legalnych Bukmacherów

Legal Bookmakers Award 2019

Best Mobile App

Mobile Trends Awards logo

Mobile Trends Awards 2020

Nomination in SPORTS & RECREATION category

20

client reviews

Clutch logo