Why use Facebook’s Android Device Year Class Library?


Year Class Library by Facebook

Building for the next billion users using the Year Class Library.

I am writing this article as I have seen many of us are not aware of this useful library.

The current user-base has around more than 10k different handsets. So you never know how your application is going to behave on different Android phones. These handsets have different sizes of Ram, the different number of CPU, etc. So on fewer handsets, your application runs fast and on the rest, it runs very slow. Although we must optimize these things, we can also write different logic for different handsets.

For writing different logic for different devices, we must know the categorization of the devices. So, this is where Facebook’s Year Class library comes in picture.


The Year Class does the categorisation on the basis of the following specifications:

  • Ram
  • Number of CPU
  • Max CPU Frequency

Facebook have clustered every phone into a group of similarly capable devices to make understanding performance easier using the above three specifications. Facebook calls this concept “year class” — essentially, in what year would a given device have been considered “high end?”.

A1d74 1jrnnumezw41swrc_tayy8q

Now, how to use this library?

Add this to your app’s build.gradle

compile 'com.facebook.device.yearclass:yearclass:x.x.x'

Then, get the year like below:

int year = YearClass.get(getApplicationContext());

After that, we can use this as below:

if (year >= 2013) {
    // Do advanced animation
} else if (year > 2010) {
    // Do simple animation
} else {
    // too slow, don't do any animations

More things that we can do with this library are:

  • Decides whether to play video or not as low-end phones cannot play it smoothly.
  • Prioritize showing the things that work best on that phone.
  • Decide how much content to load on that particular phone.
  • and much more.
With great power, comes great responsibility. So use it in the best way.

Happy Coding :)

Amit Shekhar

Also, Let’s become friends on Twitter, Linkedin, Github, Quora, and Facebook.