Andrey Vashchenko

Parse & Android: tips for junior developers

Annotation
In this article I'd like to describe my impressions of using Parse BaaS for Android app backend development and tell you about the pitfalls I encountered during the work. The first time I was advised to use this platform by my workmates when I was junior developer with experience of a single commercial project. I spent a lot of time finding out compatible libraries and thinking about different platform developer's decisions. Just in case, I'll leave all the necessary links about Parse below.
Point 1: Usage of Parse Server in connection with PostgreSQl
I used this configuration because the server was deployed on VDS hosting and the usage of MLab remote database was irrational as Roskomnadzor was trying to block Telegram in Russia and it was difficult to establish connection without VPN during the development. I had no time to set VPN up on Ubuntu server as the project was close to deadline so I decided to use local database. The PostgreSQL was chosen because I had experience working with it.
Lifehack #1: You need to import all postgis extensions right after postgres database creation to avoid type errors during database work. You can read how to connect postgis extensions to database here. When all extensions are connected you are ready to connect database to server and check that all tables created as intended.
Lifehack #2: You should use the Parse server v2.7.2 or newer. In the test project based on v2.2.5 Parse server I found on Github, everything seems to work but it turned out lat and lng values were swapped on coordinates saving.

There were 2 cases: if both coordinates were less than 90° modulo map marker was misplaced, in other case app crashed with "Lat should be between -90° and 90°" message.

The next two days I was seeking for decision. Different forums and github issues showed different solutions: to swap coordinates in Cloud-function (doesn't work!); to swap coordinates in PostgresStorageAdapter (changes led to numerous errors). The next day I checked release notes and found that the bug was fixed in version 2.7.2. So I fixed version in package. json and it started to work!

At that moment there was version 3.x.x and I tried to use it but developers did many changes to Cloud functions and there were more errors. I had no time to fix the existing code, so version 2.7.2 was suitable for me. In case of a new project better use the actual version.
Point 2: LiveQuery doesn't perform
I spent about a day to solve this problem and it was pretty strange and unobvious.

Initially the architecture was like this:
But the request wasn't unsubscribed despite method was invoked on leaving the screen. It's known that LiveQuery subscribes by request and any changes of data related to request could be tracked in callback. Unsubscription is also performed via request.

Subscription method returns the Subscriber object but it's absolutely useless as it doesn't contain unsubscribe() method and the ParseLiveQueryClient doesn't contain unsubscribe() method with Subscriber parameter. So I started to debug the unsubscribe() method step by step.

Subscriptions list is privately kept in Client. In unsubscribe() method developers iterate over this list in cycle and compare request from parameter with request from Subscription object using non-overridden equals() function that uses == operator to compare complex objects references which explains everything.

In my project there was a class that creates necessary request. Each instance of a request object has different reference so equals() didn't work and unsubscription didn't perform. So I decided to use singleton and it started to work.

Now it looks like this:
Later I had an idea to create custom manager to track subscriptions but it wasn’t released.
Summing up
Hope, this article will be useful. If you found any inaccuracies or mistakes text me. And there are links to sources that helped me:



  1. What is BaaS (in russian)
  2. What is Parse? | 5 Parse's alternatives (in russian)
  3. Parse documentation
  4. How to install and begin to use PostgreSQL on Ubuntu
  5. How to connect PostgreSQL to Parse-server
Good luck! :)
Thanks for reading!