As an Android developer I get asked a lot about fragmentation on Android and if it’s doable in dealing with it. Judging from the attention it gets in the media, the question is understandable. There is supposedly a lot to do about Android fragmentation. Every once in a while stories about the subject dominate the news.
But as an software developer and every day Android developer the question always surprises me a bit.
Nothing new here
Before I was into Android development, I build websites and web-applications. And I don’t recall people asking me about how to deal with all the screen sizes and all the different browser versions. There was IE6 of course, but somehow everybody had some sort of understanding that IE6 was the only exception.
Similar is the situation when developing applications for the desktop. Different versions of the OS, different screen sizes, different hardware. Nobody seems to wonder how the developers of MS Office have to cope with it all.
I my opinion fragmentation is nothing new. It’s more unique that you do not have to worry about it (like on iOS in a way).
So how does fragmentation manifest itself on Android and is it really a that bad?
Screen sizes
This is the obvious one. It might look like a big problem, but I think it actually isn’t.
First of all because Android gives you a lot of tools to deal with different screen sizes. Think of the densities (LDPI, MDPI, HDPI, etc..) and the layouts you can override .
Second when you specify all your dimensions in dp’s (density independent pixels) you will discover that most screens have roughly the same aspect ratio. Now you just test the on the smallest screen you want to support (say HTC Wildfire) and on the biggest screen you want to support (Samsung Galaxy S III). If it looks good on both you’re done, if not tweak a bit (mostly for the small screen).
What about tablets? Most clients I worked with in Europe are not yet paying for a tablet layout, but if you have to build a hybrid application, than the layout variants are your friend. There are a lot of guides on the http://developer.android.com that explain to you how you can build an application that adapts to the users available screen size .
Different versions of Android (API levels)
This is also a problem on iOS, but on Android it’s bigger because vendors update slowly or not at all to new versions of Android. Therefore there are more different versions of Android available in the wild than versions of iOS.
In my opinion this is the biggest problem with Android fragmentation. In practice I’m still writing apps for Android 2.2 and judging from the market share it is going to take a while before we can leave Android 2.X behind. 2.3.X has a whopping 54% market share. This means it is gonna take at least 3 more years before we can even think about developing for Android 4.X only. This is sad as the Android 4 SDK brings a lot of good new stuff, but the best stuff is backported by the support library or efforts like Actionbar Sherlock . So it is manageable.
Vendor specific bugs
This is a real problem but fortunately also very rare in my experience. I have encountered this problem only once. It was an old HTC phone running Android 2.2 and it didn’t want to parse a date while the date format was exactly as specified.
The team had a really though time finding the bug, but that was because the exception got consumed by a catch clause (which wasn’t intended to catch it). Working around such bugs has been easy but detecting them can be a pain if disregard best practices. In other words never write catch (Exception e) {}
, it is evil.
Conclusion
This has become a pretty long post. This may lead you to believe that fragmentation is a big problem, as it seems you have to account for a lot of things. I am certainly not saying that the fragmentation does not exist and you certainly have deal with it. But that said, when you stick to the best practices and build your app “the right way™” I find it doesn’t take a lot of extra effort take make your app run on all the devices and scale across all the screen sizes.
Continue reading