As you can see at the Top is the name of our Project “HelloWorld” and there are files which are inside our project. This is not different from what a visual studio developer see. I will explain the directories and files that are found here and even some important sub directories that are found in this example project.
This directory contains Java generated code and libraries. This are used by Java. In .NET or Visual studio we do come across generated code after creating a project which is not empty.
This directory is usually empty, you can store files that you might want to access in your app and when your projects create an apk, this folder will be one of the folders inside the apk
This is the same bin directory that we have in Visual studio that gets regenerated every time you compile your Project by building it. This bin folder is the one that contains the setup file for Android which is a file with an extension of .apk
This directory have external libraries that you want to use in your project. Sometimes you might want to reuse a functionality that you don’t want to redo, this is the place where you can store the libraries. The libraries in .NET comes in a form of dll’s and in Android development they come in a form of .Jar extension.
The res directory contains UI, images and other important files that will be explained later. The res directory has other directories inside it. Below is the explanation of each directory
This folder contains images, you will notice that there are five different types of Drawables. These folders contains the same image with different sizes. When creating the Project in Part 2 of this article, in the wizard there was a part where we had to upload an image. That image was sliced into smaller images of different sizes to accommodate different devices with different sizes. We don’t have this kind of functionality in visual studio.
This is where the UI are stored. In Android development, the UI and the code behind are stored in different places. The UI comes in form of XML, the same way HTML or the asp.net is. The difference is that the Android UI is .XML and the ASP.NET page is .aspx
Below is an example code of the UI or Activity
There are different kinds of layouts and that is beyond the scope of this article. If you have developed a Silverlight or a WPF application you will note as similarities. There is namespace declarations, the height and width of the screen or activity and we also have a TextView which is similar to a Label in Visual studio development.
This directory contains xml description for menus. This is rarely used especially if you have your own layout that is more flexible and attractive.
This folder contains constants, this that you want to use throughout the project that will not change. E.g. Application name on the title bar of each window or Activity, a Timer Value for a Clock etc...
The Android manifest is similar to a Web config in ASP.NET, it perform exactly the same functions. Below is an example of an Android manifest file
In the manifest file, you can see I can tell the app what is minimum version and the target version of the Android sdk that I want, I can also tell it to start an Activity and I can also tell what the name of my apk is, I can also tell it when to find an icon to launch the application. This is self-explanatory I will not go deeper on it.
NB: I placed this at the end so I explain the connection between XML and Java
This directory contains the .Java files. This Files can either be Classes or Activity classes. Now when I say Activity Classes I mean the Java Files that are coupled with an Activity. We go deeper on that subject later on. In asp.net this could be our code behind files. You know for each asp.net page there is a .cs file which is coupled with the asp.net page. These is similar to that , these are cs files , the difference here is that they are not stored in the same place as their UI file (XML) asp.net Page. Below is an example of the code
This is where some minor differences, but I will not try to teach you the languages as it will be beyond the scope of the article. On the code above, you will note that there is a class named “MainActivity” this class extends Activity. As you know Java and C# don’t support multiple inheritance, they implement or extend an interface. So here we see that part in action. If a Class extends to Activity interface this means that this is the code behind for the UI. When we move down to the code there is a method named “onCreate”, this is the same as PageLoad in asp.net, though ASP.Net has other events that gets fired before Page load, “onCreate” in Android is close to what “Page Load” is doing in asp.net.
One can ask how the code behind is connected to the XML because there is nothing in the XML UI that connects the two.
I would like to conclude part 3 here, so that I can give you time to digest what I just explained. You saw the code you did not write and you are close to coding yourself. In the next article Part 4, we will write code.