Defining the Android Manifestxml

With our introductory tour of the main components of the Android platform and development environment complete, it is time to look more closely at the fundamental Android concepts surrounding activities, views, and resources. Activities are essential because, as you learned in chapter 1, they make up the screens of your application and play a key role in the all-important Android application lifecycle. Rather than allowing any one application to wrest control of the device away from the user and from other applications, Android introduces a well-defined lifecycle to manage processes as needed. This means it is essential to understand not only how to start and stop an Android Activity but also how to suspend and resume one. Activities themselves are made up of subcomponents called views.

Views are what your users will see and interact with. Views handle layout, provide text elements for labels and feedback, provide buttons and forms for user input, and draw graphics to the screen. Views are also used to register interface

event listeners, such as those for touch-screen controls. A hierarchical collection of views is used to "compose" an Activity. You are the conductor, an Activity is your symphony, and View objects are your musicians.

Musicians need instruments, so we will stretch this analogy a bit further to bring Android resources into the mix. Views and other Android components make use of strings, colors, styles, and graphics, which are compiled into a binary form and made available to applications as resources. The automatically generated R.java class, which was introduced in chapter 1, provides a reference to individual resources and is the bridge between binary references and source. The R class is used, for example, to grab a string or a color and add it to a View. The relationship among activities, views, and resources is depicted in figure 3.1.

Along with the components you use to build an application—views, resources, and activities—Android includes the manifest file you were introduced to in chapter 1, AndroidManifest. xml. This XML file describes where your application begins, what its permissions are, and what activities (and services and receivers, which you will see in the next two chapters) it includes. Because this file is central to every Android application, we are going to address it further in this chapter, and we will come back to it frequently in later parts of the book. The manifest is the one-stop shop for the platform to boot and manage your application.

Overall, if you have done any development involving Uls of any kind on any platform, the concepts activities, views, and resources represent may be somewhat familiar or intuitive, at least on a fundamental level. The way these concepts are implemented in Android is, nevertheless, somewhat unique—and this is where we hope to shed some light. Here we will be introducing a sample application that we will use to walk through these concepts, beginning with getting past the theory and into the code to build an Activity.

0 0

Post a comment