Android development is mainly done in Java, which is the usual language used to teach programming in computer science courses. If you don't know Java but already know another language, you can easily pick up Java along the way.The development environment we're going to use is the new Android Studio which was announced during the latest Google Developer’s Conference (I/O 2013).
Our goal for this week's mini project is to create an app that displays "Hello AndroidPIT" on the screen of your Android device.
The first thing you need to do is to download Android Studio.
I’ll be using Ubuntu Linux for this tutorial, but you can also use Windows or Mac. You just need to adapt the instructions to your particular situation. Since I don’t use Windows or Mac, unfortunately, I can’t provide you with instructions.
Android Studio is written in Java and you are also going to write in Java for this tutorial so you need to install the Java Development Kit (JDK) also. Follow this link and download the version for your system:
We will deploy your “Hello” app directly into your phone. For that reason, you need to enable USB debugging on your device, which is only available if you have your device in developer mode.
To enable “Developer mode” you need to go to Settings > About phone and tap “Build number” until a toast displays that you're a developer. Then, in the previous screen you'll see a new entry called "Developer options" and there you should enable "USB debugging".
Creating your first Android project
So, assuming that you have already installed Android Studio, let’s create a new project. I’ll use screenshots to make it easier for you to follow up with the steps.
We’re going to name our project HelloAndroidPIT. Module name, Package name and Project Location get filled in automatically and you don’t need to change them.
What we’re going to change is the minimum required SDK to API 15 (Android 4.0.3 IceCreamSandwich). Yes, we’re going to ignore Android 2.3 (API 8) which will hopefully die by mid-2014. I know that currently Android 2.3 still has 26.3% of market share, but I’m confident that it will start dropping very quickly after Christmas. If you want to know more about the percentage of users each Android version has, please consult this page.
Our target SDK will be KitKat and you can choose either Java 6 or 7. Support for Java 7 is very recent and some features are only available if your minimum required SDK is 19. Which won’t happen soon probably.
Since we’re not going to create a custom icon, please uncheck that checkbox.
After pressing next, you’ll see this screen:
Just press Next again and you’ll see another screen…
Ignore all those fields and just press Finish.
After completing these steps, connect your device to your computer, press the green Play button and the auto-generated code should compile, get deployed to your device and run.
Now that the app is running it should display “Hello world”. Saying hello to the world is nice, but we'll say hello to AndroidPIT also.
Now, to say hello to AndroidPIT you just need to open the strings.xml file inside your values folder which is found inside your res folder. You should see the string there which says “Hello World!”. Simply change it to Hello AndroidPIT and press Play again.
Localization (usually abbreviated to L10n) is very important nowadays. We're not in the age where software was only available in English anymore, so it's important to know how Android deals with L10n.
Since I'm from Lisbon, Portugal, living in Berlin, Germany but speaking English everyday at the office (yes, German is not easy to learn), we will learn how to say “hello” in all those three languages.
If you look to your values folder in your project you see that there is a strings.xml file there.
To add other languages you just need to add a values folder followed by a dash and the codename of the country to your res folder inside your project, for example: values-pt and values-de. Copy the strings.xml file from the default values folder to each of those two folders and then edit each of those files and replace “Hello AndroidPIT” with “Hallo AndroidPIT” and “Olá AndroidPIT” for German (values-de) and Portuguese (values-pt) respectively.
If you change the language on your device and run the app again, you should see the app translated.
I hope that this tutorial has made you excited to learn about Android development. The next article that I might possibly write will be about displaying how to display AndroidPIT news articles. What do you think about that?
Please let me know if you liked the article in the comments below.