John Petitto About Blog

RxJava for Android Developers (Talk)

Last week I gave a talk on RxJava at the Austin Droids meetup. It marked the group’s fifth year in existence (congrats to the organizers!) and was also the most attended meetup in its history. I was hoping to have the talk recorded but after some technical issues we weren’t able to make it happen. I posted the slides online after the talk but I don’t think they stand too well on their own. So I’ve taken the time to write out my narrative to the slides below.


Dependency Management for Android Libraries

When Android developers choose a library for their project, they aren’t merely looking for things such as features, usability, performance, documentation and support. They also care how large the library is and the number of methods it’s going to add. As a project grows and so does its dependencies, developers feel the pressure to keep their app below the 65k method limit. Proguard is too slow to wait for with non-release builds and developers try to avoid multidex like the plague. It’s therefore crucial that library authors be conscious about the size of their projects.

The simplest approach to keeping your library’s method count down is to not include any unnecessary dependencies. Any dependencies you do include will transitively be added to your users’ projects. For example, if you need a few simple utility methods, such as closing a resource quietly, don’t go adding Guava just to do this. Instead, roll your own or extract it from an existing library (make sure to give credit!). Your users will most definitely appreciate the exclusion of over 14k methods when you only needed a few.

Why I Don't Use Realm Anymore

If you haven’t heard of Realm before, it’s a mobile database technology for Android (iOS too). Opposed to SQLite, it allows you to work with data objects directly at the persistence layer. On top of that, there is a powerful functional-style query API and effort has been made to make it even faster than traditional SQLite operations. It was for these reasons I decided to give Realm a try.

When I first used Realm around a year ago, my initial impressions were quite good. I needed to persist some user data locally on the phone, but it was a bit too complex for SharedPreferences. Realm allowed me to quickly and cleanly write the necessary code to do this. There was no need to write any of the extra cruft that would have been required with SQLite.

The Great Enum Debate

Since the early days of Android, there has been an ongoing debate about whether or not enums should be used due to their overhead in memory consumption. Google has long been in favor of using int constants as a substitute and even go as far as saying enums should be strictly avoided. A memory comparison between the two methods is neatly outlined in this Stack Overflow answer.

Recently, this debate has come back into the spotlight. One reason for this is that Google has been pushing the issue lately as part of their #perfmatters campaign, which educates Android developers on performance related topics. They’ve also released a new support annotations library containing the @IntDef annotation, which provides compile-time type checking for int constants (I wrote an article on it here). As a result of all of this, there has been backlash from some prominent community members regarding the merit of Google’s stance on enums.