Develop Your First Android App
If you have come to this page, it means you have no or very mild knowledge of android programming. You want to learn android programming so that you can develop high potential apps. The apps you develop can be provided as free apps, paid apps (which could be purchased by users) or monetize them to earn money.
The landscape of technology is changing very fast around the world. Its changing at fast pace in Pakistan as well. Alot of startups are emerging with new ideas which they put in digital format in the form of android, IOS or microsoft mobile applications. This is the must have opportunity to seize to enter in the world of mobile apps technology and make an earning or build your career.
We will not go into much details of how to develop advanced applications, but rather giving you a kick start to have hands on to develop your first android app. Once you learned to develop your first android app, there is nothing stopping you to go further. Google, Bing and Yahoo is full of android application tutorials which you can read and follow and develop competence in yourself.
Your First Android App Development
To start with your first android app development, there is a list of pre-requisites to be followed. Here are the following things you need to start developing your first android app.
PC Dual Core or higher (32 or 64 bit)
2 GB minimum RAM
Windows XP (not tested ) 7 or higher
A good internet connection
Android phone with USB cable for testing or PC android emulator
Android eclipse SDK (select 32 bit or 64 bit depending on your computer processor architecture)
If you don’t have android phone with usb cable for testing, you can use android PC emulator. It might be slow if you have 2 GB RAM and dual core processor. If you have high end machine like Core 2 Duo or higher and 4GB+ RAM, you will have fast android pc emulator to test your application. But any ways in the end its good to have android phone to test your application. Application speed differs in PC android emulator and that in android phone.
Also If you have a phone with old android version you may need to select lower API to use in application development as it may not run in your old phone. If you have Android ICS sandwich, Jelly beans or KitKat and higher, then every thing will go smoothly.
Downloading Android Eclipse SDK
SDK refers to Software Development Kit. SDK is provided by every platform for building applications or games. Apple provides it own SDK, Microsoft provides its own and the same goes for black berry, Google etc. SDK contains IDE (Integrated development environment) important build tools, documentation, emulators and libraries which are used to develop application. So to develop your first android app, lets go first by downloading android sdk from here. Click on Download Eclipse ADT button and in next page select the 32 bit or 64 bit depending on your computer configuration. How you can check if your PC is 32 bit or 64 bit? Its fairly easy by right clicking on My Computer and clicking properties. You will see in the window your computer configuration information.
Once downloaded, unzip it to your C drive or where ever your windows is installed. Mine one is unzipped in C drive root folder Android.
Running Android SDK Manager
Now if you go to the unzipped folder of your android sdk, you will see a program SDK Manager. Double click on it and wait till it completely loads. It will fetch the latest as well as old SDK APIs. Following is a snap of how it looks like.
You can see a long list of APIs from the above picture. Android 5.0 (API 21) is the latest lollipop release just announced by Google. Android 4.4W is Kitkat release with wearable support like Google watch or Google Glass. Then comes the 4.4.2 (API 19) is Android KitKat for mobile phones. Android 4.3 is Jelly Beans and so on. On the top of the list you can see Tools. Tools provide a bunch of components responsible for compiling and building your android application. So first of all we need to select tools as shown below.
You can see a long list of APIs from the above picture. Android 5.0 (API 21) is the latest lollipop release just announced by Google. Android 4.4W is Kitkat release with wearable support like Google watch or Google Glass. Then comes the 4.4.2 (API 19) is Android KitKat for mobile phones. Android 4.3 is Jelly Beans and so on. On the top of the list you can see Tools. Tools provide a bunch of components responsible for compiling and building your android application. So first of all we need to select tools as shown above.
You can click on Tools and all the sub components of Tools will be automatically selected. After that you need to decide which API you have to use as a target. Right now Android 5.o Lollipop is the latest release as can be seen from above snapshot. For this tutorial we would be using Android 4.4.2 as a target. But you can see the components in Android 5.0 and Android 4.4W in below image.
As you can see from the list of both APIs there are alot of stuff which you can select. It depends all on your needs. I will explain few parts which are useful from our perspective. First of all the most important part is SDK Platform selection. SDK Platform includes all the necessary libraries that would be used to develop your first android app. Documentation of course is very important during development of your application to get references. Other important part is System Image. System Image is like virtual OS which runs in emulator. It has the same resemblance like your android phone OS. So this part must be selected as you want to see your application run in android emulator for PC. In Android 4.4W you can see the system images are for Android Wear. As discussed earlier, this system image will provide android running on wearable devices like Watch, Glasses etc. So its not for our use at the moment as we are discussing android application for mobile phones. So If you want to develop application based on Android 5.o lollipop and want backward support, then you need to select SDK Platform in the older APIs.
This tutorial is based on target SDK Android 5.0 lollipop and we want to compile it with Android 4.4. So we will select Tools, and the rest of the items as mentioned in above pictures. We will not select the items highlighted in orange color rectangle. We will use Android 5.0 System image both for ARM and Intel architecture. Once selected click Install button as mentioned in above figure, all the packages will be installed. Sit back and have a coffee till it finishes.
Creating HelloWorld Project
Once all the items are downloaded and installed, its time to develop your first android app. Go to the SDK unzipped folder and you will find another folder call eclipse. Open eclipse folder and then double click on eclipse.exe. If it gives error about JVM (Java virtual machine) run time, then you need to download and install java. You can easily find it by googling it. Remember to download 32 or 64 bit java depending on your system architecture.
Once eclipse is open, click on File -> Android Application Project
Configuring Project Properties
New window will appear asking for configuration information about this project
You need to give a name to your application, in my case I have put “My Famous HelloWorld App”. Project name will be auto completed. Package name you need to modify as the default package usually starts with com.example. It must be changed to some thing useful like your company name or team name etc. Example could be com.rockstar.myfamoushelloworldapp.
After that the below selection is automatic. Minimum Required SDK means this is the minimum it will support. Target SDK means this application will run on Android 5.0 Lollipop (in picture its 4.x L which was in beta version). Compile with means your project will be compiled with API 20 Android 4.4 libraries. Theme is the look of your application. You can change it later. Once you are done click Next.
Setting Project Activity Properties
Another Dialog will appear confirming few things like Activity and icon. Activity is like the execution point of application. In C , or C++ it usually starts with int main() and can have multiple threads to do some specific tasks. In Android which is based on java has the same concept, but they named it as activity. There can be multiple activities in your android application. Click next to proceed
Setting App Launhcer Icons
After clicking next you will be presented with launcher icons. You can select icons of your choice from your PC. I have set them as default. Click next again.
Creating Activity Type
A new dialog will appear asking for activity selection type. The main User Interface for your android app. I have selected Blank Activity. Click Next to Continue.
Finishing Project Setup
At the end a final dialog will appear summarizing your Activity name as shown below. Click Finish to complete.
Project overview in Eclipse
Once you have clicked finish, it will take some time to setup your project in eclipse. Your project would look like below. Click Image to enlarge.
You can see two tabs in the above picture i.e. Activity_main.xml and MainActivity.Java. Activity_main.xml is the xml file containing your android application User Interface information. More information can be found from the web. MainActivity.java is the main activity file where you can start writing code for your application.
Adding Android Virtual Device (Android emulator)
Adding Android Virtual Device is our next step. Lets add Android virtual device by following below images.
Select or Create a new android virtual device
Create Android virtual device from device definition list
Android Virtual Device configuration
Click Ok and you have created android virtual device which will run as emulator on android PC. You can use ARM if you don’t have Intel Atom processor.
9. Now lets run our application, by right clicking on our project in eclipse and then going down to Run as -> Android
After sometime the emulator will startup and will trigger your application. If it didn’t trigger your helloworld application, you can go to the menu in android emulator find your application there as shown below.
Emulator Running Android OS (System Image)
Android OS running android emulator for PC same as like your mobile phone android OS. Click image to enlarge.
Running Application on Emulator
Here we trigger our android application from the list. You can find your application by clicking menu button in emulator (as I did) and search for helloworld application. Click image to enlarge.
That’s it for your first android app.
Like it and share it with your friends, so that they can have their hands on their first android app.