Chapter 6

Enhancing Your First Project

The AndroidManifest.xml file that Android generated for your first project gets the job done. However, for a production application, you may wish to consider adding a few attributes and elements, such as those described in this chapter.

Supporting Multiple Screen Sizes

Android devices come with a wide range of screen sizes, from 2.8-inch tiny smartphones to 46-inch Google TVs. Android divides these into four categories, based on physical screen size and the distance at which they are usually viewed:

  • Small: Under 3 inches (7.5 cm), at least 426×320dp resolution
  • Normal: 3 inches (7.5 cm) to around 4.5 inches (11.5 cm), at least 470×320dp resolution
  • Large: 4.5 inches (11.5 cm) to around 10 inches (25 cm), at least 640×480dp resolution
  • Extra-large: Over 10 inches (25 cm), at least 960×720dp resolution

By default, your application will not support small screens, will support normal screens, and may support large and extra-large screens via some code built into Android that automates conversion, scaling, and resizing of an application onto larger screens.

To truly support all the screen sizes you want to target, you should consider adding a <supports-screens> element in your manifest file. This enumerates the screen sizes for which you have explicit support. For example, if you want to support small screens, you need to include the <supports-screens> element. Similarly, if you are providing custom UI support for large or extra-large screens, you will want to have the <supports-screens> element with appropriate subelements. So, while the default settings in the starting manifest file work, you should consider adding support for handling multiple screen sizes.

Much more information about providing solid support for all screen sizes can be found in Chapter 25.

Specifying Versions

As noted in the previous chapter, your manifest already contains some version information about your application's version. However, you probably want to add to your AndroidManifest.xml file a <uses-sdk> element as a child of the <manifest> element, to specify which versions of Android your application supports. By default, your application is assumed to support every Android version from 1.0 to the current 3.0 and onward to any version in the future. Most likely, that is not what you want.

The most important attribute for your <uses-sdk> element is android:minSdkVersion. This indicates what is the oldest version of Android for which you offer support. If you like, it communicates the oldest version with which you are testing your application. The value of the attribute is an integer representing the Android SDK version:

  • 1: Android 1.0
  • 2: Android 1.1
  • 3: Android 1.5
  • 4: Android 1.6
  • 5: Android 2.0
  • 6: Android 2.0.1
  • 7: Android 2.1
  • 8: Android 2.2
  • 9: Android 2.3
  • 10: Android 2.3.3
  • 11: Android 3.0
  • 12: Android 3.1
  • 13: Android 3.2
  • 14: Android 4.0

So, if you are testing your application only on Android 2.1 and newer versions of Android, you would set the android:minSdkVersion attribute to 7.

From Android 3.2 onward, an alternative method is provided to more accurately specify the space requirements of your screen layouts. These attributes specify the smallest width, sw<N>dp, available width, w<N>dp, and available height, h<N>dp (where N is the pixel count). At first, using these prescriptive options may seem more complicated, but for many designers it is more natural to design a layout and set of features, and then determine the minimum and optimum sizes to the nearest pixel for presentation requirements.

You may also wish to specify an android:targetSdkVersion attribute. This indicates which version of Android you are targeting as you are writing your code. If your application is run on a newer version of Android, Android may do some things to try to improve compatibility of your code with respect to changes made in the newer Android. So, for example, you might specify android:targetSdkVersion="10", indicating you are writing your application with Android 2.3.3 in mind; if your app someday is run on an Android 3.0 device, Android may take some extra steps to make sure your 2.3.3-centric code runs correctly on the 3.0 device. In particular, to get a tablet look and feel when running on an Android 3.0 (or higher) tablet, you need to specify a target SDK version of 11 or higher. This topic will be covered in more detail in Chapters 26 and 27.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.36