The manifest file is an XML file that describes the app to the operating system and virtual machine. The name of the file is always the same, AndroidManifest.xml. When you're looking at your project in the Android view, you'll always find it under the AppManifest folder. The file's root element is always named manifest. It contains a child element named application and can contain other child elements as well. The manifest element starts with a namespace declaration with a prefix of android.
- [Instructor] The Android manifest file is an XML file that describes the app to the operating system and the application framework. The name of the file is always the same, AndroidManifest.xml, and there's one of these files for each module in a project. My project only has a single module, the app module, and therefore, only one manifest file. The file's root element is always named manifest, and there's a required name space declaration. That name space prefix is then used on all of these attributes throughout the file.
The package attribute of the manifest points to the unique id of this application. Within the manifest, there's an application child element, and it has a number of properties that control the behavior and appearance of the app for the user. The allowBackup attribute turns on or turns off the backup feature that was introduced recently in Android, which allows certain data files to be uploaded to Google servers and then restored when an application is reinstalled. The icon attribute points to a graphic.
This is something called a resource id. The prefix starting with the @ character, points to one of the resource folders in the application module. If I go to the Source directory under the module, then to Main, and then to Res for Resources, I'll see that there are five mipmap directories. Each of the suffixes, starting with hdpi, then mdpi, is for a particular pixel density. So there are five different versions of what's known as the launcher icon.
And I'll show you how to create your own launcher icon towards the end of this course. You can double click on one of these files to see what the graphic looks like, and a brand new Android Studio project will have a launcher icon that looks like the Android Robot. This one is for extra, extra, extra high dpi devices. This one is for extra, extra high, extra high, medium, and high. And when you open each of these files, you can look in the top-right corner and see what the dimensions are.
There's one that's 48 x 48 pixels, one that's 96 x 96, and so on. With any resource, you can hold down the Control key on Windows, or the Command key on Mac, and then click to get to the appropriate file. And if there's more than one file that's referenced by that string, you'll see a list pop up, and you can choose the one you want to look at. Next is the label. There's a label applied to both the application, and to the first activity. The one applied to the activity is the one that's shown on the launcher screen on the device.
But right now, both are using the same string. In both cases they're using a string resource. Once again, we're starting with a resource prefix, starting with the @ character, and then string. This prefix points to files that are in the values directory, and specifically in this case, to values that are defined in the strings.xml file. Here's the app name resource, and here's the use of that resource. Once again I can hold down Control or Command, and click, and I'll jump to that value.
This is the id of the resource, and this is its value. Now with string resources, the name of the file doesn't matter. You can actually create multiple string resource files in the values directory. What does matter is the name of the element string, and the identifier for that particular resource. The supportsRtl attribute controls right-to-left display. Starting in Android 4.4, the Android application framework changed how it worked with objects that were placed next to each other horizontally.
In the past, these positions were known as left and right. With the more recent versions of Android, these were referred to as Starting and Ending. And so in conventional left-to-right layout, Starting would be on the left, and Ending would be on the right, and in right-to-left layouts, they would go in the opposite direction. When you create a brand new Android Studio project, this feature is turned on. But if you don't want to support it, you can change this value to false. Next is the application's theme. This is defined in the styles.xml file.
You'll see in the name attribute of the style, that the value is set to AppTheme, and the parent is set to an existing theme that's a part of the Android SDK. Within the app theme, there are colors that are defined. These colors are a part of the material design framework. And within those, there are references to other colors. And these are defined in the colors.xml file. You can change these colors to change how your application looks. And there are a lot of resources on the Web that let you build these color sets to match material design requirements.
Coming back to the manifest, those are the attributes that are set up by default in a new application. Within each application you'll have at least one activity that's defined. Each activity must be registered in the application manifest. The name refers to the Java class that implements that activity. The dot is a shorthand code that means the base package. So if I hold down the Control or Command key, and click on that id, I jump to the appropriate Java class.
The label, once again, refers to the string resource app name, and the theme overrides whatever you've set in the theme for the application. In this case, the theme of this activity is something called AppTheme.NoActionBar. The intent filter controls how this activity can be used. And each application, should have one activity that's marked as the launcher activity. That's what this category is doing. So when you install the application on a device, and the user touches or clicks on an icon for that application, this is the activity that's going to start up.
Each time you add a new activity to the application, you need to register it in this application manifest. And the same thing is true of certain other components, such as services, and permissions, and I'll talk about those toward the end of this course. So that's an introduction to the manifest. It's a critical part of your application, defining your activities, your services, your permissions, and other elements that go into making up your Android app.
- Installing Android Studio
- Creating your first Android Studio project
- Managing profile files, including Gradle scripts and support libraries
- Defining screens with activities
- Implementing designs in XML layouts