Wednesday 7 September 2016

Android Tutorial #1

Android

Android is a mobile Operating System (OS) developed by Google and it's based on the Linux Kernel. It's designed mainly for touchscreen phones. It is an open source initiative and the Android source code is released by Google under the Open Source licences.

Components

So at a very abstract level developing Android applications consists of two components :
1) Resource files.
2) Java files.

1.Resource Files

Resource files are stored under the res directory and can be considered as the skeleton of the Android application.

2.Java Files

Java files are stored in the java directory and are used to add life to the Android application and make it respond to dynamic events.


Other than this broad categorisation there are other types of files which will be explained in the coming parts.


Example

Without spending more time on the nitty gritty's lets begin writing your first Android application.

Since Android has stopped support for Eclipse I urge you to use Android Studio and this tutorial will contain screenshots of projects in Android studio.


After installing Android Studio and setting up your SDK, start Android Studio.



 Click on the "Start a new Android Studio project " option under "Quick Start".


Fill up the field "Application name" with something suitable.
"Company Domain" should be the web domain name of your company so that it is unique, however it is not necessary for the domain to exists. The "Package name" depends on the "Company Domain" you provide which in turn is used to name your package and while uploading your .apk file to the Google Playstore. So as of now you needn't worry about it.

After filling up the data suitably click "Next".


Check the "Phone and Tablet" checkbox since we are going to develop and Android application for a phone/tablet in this tutorial.

The other check boxes need to be checked when developing applications for the respective devices as suggested in the name. Wear for watches, TV for televisions, etc.

 Depending on the SDK you have downloaded set up the "Minimum SDK"."The Minimum SDK" means that the application we are building will work only on devices running at least this version of Android.

Click the next button after filling up all the details.


Activity
An Activity is an application component that provides a screen with which users can interact in order to do something , such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

Android Studio allows us to chose from a set of Activity templates. We will choose the "Blank Activity" for now and we will use the other templates in further tutorials.

Click the "Next" button after choosing the "Blank Activity".


Usually most Android applications begin with an Activity called "MainActivity". This name can be changed. For the purpose of maintaining uniformity it will be kept as "MainActivity" in this example.
Each Activity has a Layout file (XML Layout) associated with it.
The field "Layout Name" denotes the name of the XML Layout associated with this Activity. 
As the complexity of your program increases and more complex components are added it becomes difficult to maintain the code, hence the prefix "activity" is added before the layout name. It is not compulsory but it is recommended.
The field "Menu Resource Name" contains the name of an XML Resource file. This file contains a number of constants which are used to populate and Options Menu, Context Menu, submenu, etc.
These constants cane be referenced from the Java files.

Click "Finish" to create your First Android project.






Connect an Android device to your computer. As you connect the device you will get a pop-up asking you to enable "USB Debugging". Enable USB Debugging on your device.
Click the Green Play button which is within the red circle in the previous screenshot.
If you do not have an android device you can create an Android Virtual Device by clicking on AVD which is within the blue circle in the previous screenshot.
Click here to learn how to create your Android Virtual Device.

Congratulations!!

You successfully created your first Android Application.
The next tutorial will contain a detailed analysis of the code explaining key concepts. 
Until then
DREAM OF CODE.

No comments:

Post a Comment