Hey! My name is Jille van der Weerd. Recently I was asked to build the Android counterpart for an iOS app I made, so I had to dive into the rabbit hole that is Android development. Working with a new IDE, a new language and a whole new community of people to learn from, it was an eventful journey. The app is now nearly finished, and I decided to write down some of the important things to note when making the same leap from iOS to Android development.

Note: I don’t claim to know everything about the things I write about. These are just my findings, and I hope some people can learn from them. If you have any suggestions or criticism, please let me know.

A quick introduction

Just under a year ago I dropped out of my Computer Science (CS) education. That’s when I started teaching myself Swift and where my journey began. Since then I’ve built a series of apps that never saw the light of day and I’ve landed a job as an iOS developer. When making this Android application, I ran into a lot of issues because I got used to having certain features from Swift. This article is meant to give some clarity on how to do those things when migrating to Android, and hopefully give Android developers an insight in potential libraries to develop.

The Codable Protocol

We’ve only had it for a few months, but it saves so much time and makes my code so much more readable. I didn’t really get around to using it for a long time, but then a friend of mine told me about how awesome it is and now I try to use it whenever I can. In Swift, the code below is enough to decode a JSON string to an object, or even an array of objects.

Converting JSON to an object is so easy thanks to codable

I haven’t found an equivalent to this in Kotlin/Java. Undoubtedly, there is a library that allows me to do something similar to this, but I prefer to use as few libraries as possible. In my Android app, I’m stuck to converting the JSON string to a Map and retrieving all properties from it line by line, increasing the workload significantly when changes to the backend occur.

Grand Central Dispatch

I didn’t know I could miss Grand Central Dispatch since I haven’t even scratched the surface of multithreading, but when I wanted to do a simple asynchronous network request on Android, I ran into a lot of trouble.

In Kotlin, I have to subclass AsyncTask to do a network request for an image asynchronously.

Having to subclass something for a task so trivial doesn’t feel “Swifty” at all, mainly because executing a task asynchronously in Swift is achieved simply by writing this block around it:

Asynchronous requests made easy

Now, I’m sure there’s a better way to do this. My main annoyance hereis that I’d have to subclass AsyncTask for every different kind of request I want to make, whereas in Swift I can just execute whatever request I want in the above block and I’m set. It just feels like the logic approach.

Interface Builder

Love it or hate it, Xcode’s Interface Builder is a great tool for helping you visually layout views. Androids wildly different view structure (fragments? layouts? XML?) greatly contributes to this. I got the hang of building views in Xcode in under a week, and using constraints feels natural. If I want/need to add another layer of depth to this, I can use priorities. In Android Studio, the

Playing with the values in this window will open up a whole new world.

Activity Designer(?) uses some sort of relative values for constraints, where setting all layout margins to 8dp can result in them being different distances from the edge of the screen. And building the layouts in Android with XML is a blessing and a curse. While it’s great to layout your views with code, and it gives you a lot of freedom as to what you can do, I had the option to do so in Xcode while also using the great Interface Builder system.

HTTP GET Requests

In Swift, the first application I built used GET requests from an API, so naturally, I assumed doing the same in Android would be a piece of cake. Right? That’s where I was wrong. In Swift, implementing the basic functionality of making a GET request and retrieving the JSON file can easily be achieved by doing this:

However, In Android things are very different, daunting even. This is the Kotlin code I currently use to make a GET request and retrieving the JSON:

…and this is just the subclass. When we actually want to perform the request, we still need to write this:

HttpGetRequest().execute("your api url here").get()

This isn’t necessarily all that complicated, but it’s a lot more difficult than the approach taken in Swift.