Beer and Xamarin.Forms – Anatomy of a Xamarin.Android Project

In this lesson

  • Xamarin Components and Nuget
  • Drawable Resources
  • Values
  • Android Manifest file and Permissions
04:47 C# 100

Transcript

Tap on time to skip ahead

00:10

Let’s take a look at what Xamarin Studio has generated for our Android application. If I expand out our project, we’ll see that we have a variety of different folders. If we double click on the Components folder, we’ll see all the different type of Xamarin Components that we can get from the Xamarin Components Store. If I click on Get More Components, it will launch the Xamarin Components Store and I can browse and search for different types of Xamarin Components that have been provided by Xamarin as well as the Xamarin community.

00:44

The next folder to note is the Packages folder. Here if we double click on it, instead of opening up the Xamarin Components Store, we instead get the NuGet Gallery browser. Here, much like with any sort of Xamarin project, I can search for different types of NuGet packages to install into my project. For this project, we will be using Newtonsoft Json.NET library to parse and serialize models to and from Json. I’m going to go ahead and select this one and add it to my project.

01:19

After packages, we have the Assets folder. If we expand this, we’ll just see this AboutAssets text file. In this folder, you usually put things like xml files or any sort of static files that your app might need to read.

01:34

If we take a look at Resources, this is where a lot of the Android UI comes from. If you take a look at the drawable folder, you’ll see that we have our pre-built, or prepackaged, icon that comes with our application generated by Xamarin. But we might also want to put various other types of images that our application will use like icons or background images.

01:58

Something that’s kind of interesting about an Android application is that there’s multiple versions of this drawable folder. The reason we have multiple versions is each one of these corresponds to different display resolutions. If we were just to have one drawable at 72dpi, whenever we’re on a retina display type Android device, it would look extremely pixelated. Nor do we want our low res device loading in high res images. By organizing our drawables like this, we can optimize images for each type of Android device out there.

02:33

In the Layout folder, this is where we put in our various xml files that will describe our application’s UI. Then we also have the Values folder, this folder is where we’ll put things in the future like strings.xml that will have different things like button labels, form field labels, things of that nature that will lend itself to localization.

02:56

Some other values that people use are the dimensions.xml file where a lot of you specify various dimensions like gutter space, heading space, things of that nature.

03:08

The next item that we want to look at is the MainActivity. An Activity is a screen in Android, it is similar to UIViewController in iOS. If we open it up and take a look at the source code we can see that it’s kicking off forms as well as loading our application.

03:25

One other key thing that we should also take a look at is the Android Manifest. The Android Manifest acts as a metadata file that has different elements of information like application name, what kind of namespace/package we want our application to have for the Android Play store, we can also specify our application icon, our app’s version number, we can also specify what’s the minimum Android version that we will support. We will also specify what Android version that we are actually going to build against. We can specify install location as well as whatever permissions we’ll need in our application.

04:06

Before Android Marshmallow, you could just specify the permissions here and when the person would instal the application they would be presented with, “do you want to allow the application to do such and such?” Now with Marshmallow, you actually have to request these permissions as they are needed. Something to keep in mind.

04:24

One other element that I forgot to mention is that if we take a look at the existing packages installed for our Android application, the Xamarin.Android.Support NuGet packages allows our application to be reverse compatible with previous versions of Android, hence why it’s automatically installed.