Chapter 11. Avoiding fragmentation
Fragmentation is a serious issue for Android developers. In this chapter, we’ll look at some tips on how to achieve certain tasks and still be backward compatible with older versions.
Since the early beginnings of Android, the whole system has had a status bar at the top of the screen. In Android Honeycomb, the status bar was moved to the bottom of the screen.
Applications such as games or image viewers need the full attention of the user, and most of them take the whole screen to display themselves. For instance, in the default Gallery application, when you click on an image, it’s shown full-screen without any other content.
Imagine you need to provide this feature in your application, and it needs to be compatible with every Android version. In this hack, we’ll build a simple toy application that will have a red background and, when we press it, the application will enter lights-out mode. We’ll take care of Android 2.x and 3.x separately, but then we’ll merge them into a single implementation.
Let’s build the application with Android 2.x code first. In Android 2.x, we have the concept of full-screen mode. The idea behind full-screen mode is to allow the application’s window to use the entire display space.
We’re also interested in another concept: the application’s title. The application’s title is the gray bar we get on the upper part of the screen.