Android application development tutorial for beginners using eclipse pdf


Android – A beginner’s guide

Android application development tutorial for beginners using eclipse pdf1 Android application development tutorial for beginners using eclipse pdf


This tutorial is really a beginning point for developing Android applications. It’ll explain the fundamentals from the Android SDK (Software Development Package) and just how for doing things with Eclipse. To know this tutorial, you don’t have to have understanding about programming in Java, but it may be useful for more programming to know the fundamentals of object orientated programming. This tutorial describes Android beginners how you can create an Android Project in Eclipse, use assets, and make some first code.
Setup Eclipse and also the Android SDK

If you do not curently have a running atmosphere to build up Android applications, do as instructed only at that link.

Hint: PATH means the road Atmosphere Variable. In Home windows, you’ll find it under “User InterfaceOrProgramOrSophisticated System Configurations/Atmosphere Variables” within the lower list box. You should check what form of Java is installed, by pointed in the command line and typing java -version.
Let us Get Began

Now you want to create our first application, that is (of course) a Hello World application. To begin with, start Eclipse. Then choose “File/New/Project”. Within the “New Project” dialog, choose “Android/Android Project” and click on “Next”.

Here you are able to setup the project. To begin with, we have to provide the project a title, so type “Hello World” within the title box. Next you need to choose the Android version you need to use. Ideas choose version 5.2. With within the last column, we want the API Version 8 with this Android version, therefore we type an “8″ within the Min SDK Version box. Also, the project requires an application title. (Observe that this title can also be utilized in code, therefore the title shouldn’t have any whitespaces). Usually, you apply the project title and remove all whitespaces (e.g., “helloworld” with this project). Next, you need to define the package from the project. We’ll use “com.test.helloworld” here (a deal can group multiple classes to learn more, see here). A minimum of, you’ll need a reputation for the game (one Application may have multiple Activities they’re just like a single part/screen from the application). Within this example, we just use “HelloWorldApp”.

Before we are able to finally start our first project, we have to produce a configuration. This configuration identifies to which conditions the application is going to be began. E.g., you are able to control the network speed the emulator/application may use. Also, you are able to distinct emulators to check the application with various versions of Android or perhaps in different screen dimensions. To produce the configuration, visit “Run/Run Designs”. Now click on the “Android Application” tab in the side and so the New button over the tabs. Call the brand new configuration “HelloWorldConfig” and choose our project within the Browse button. Now move onto the prospective tab. Here you are able to choose the network speed and which emulator is going to be used.

Since we’ve not produced an emulator till now, we have to do this first. Click on the automatic control to allow the buttons in the side after which click the manager-button. Here, click on the new button right to produce a new emulator. Within the following screen, you are able to enter a reputation for the emulator (I have tried personally “DefaultAndroidEmulator”) and specify the particulars (like Android version, Sdcard size, plus much more). You are able to control every little detail from the emulator within the hardware section.

When you are completed with that, click “Create AVD” and shut the manager window. We now have effectively produced the run designs. Click “Apply” and shut the designs. A minimum of run the first Android project.

Notice: It might take the emulator a while to obtain began, so have patience! Also, I’ve popped the look to ensure that you cannot begin to see the keyboard or even the D-pad.

Congratulations! You simply produced the first Application!

As we have setup everything, it’s (finally) time for you to really getting began using the code, because everyone knows: Coding is fun!

Before we are able to really jump in to the Java code, we have to comprehend the structure of the Android Application. See your Package Explorer and enlarge the “Hello World” project. You will notice five folders and 2 files. Let us get began using the one of these simple two files, the AndroidManifest file. This file consists of all the details regarding your project, such as the icon, the title from the author. To spread out it, create a right click it and select “Open With/Android Manifest Editor”. Within the approaching tab, you are able to specify the package title and also the form of any project. At the end, you’ll find additional tabs. I believe the majority of the configurations you’ll find are virtually self-explanatory. Note the @ before some characteristics. This implies that the next string is really a mention of the an origin. You’ll find the assets within the “res” folder of the project. Should you enlarge it, you will see that it’s some subfolders. To be precise, the res folder might have seven kinds of subfolders: values, drawable, layout, animations, xml, styles, and raw.

Let us concentrate on the values folder first. Here you are able to store a myriad of simple assets (like strings, colors, amounts, dimensions, arrays, etc.). Automatically, there is a strings.xml file inside. Whenever you open it up (with right click, “Open with/Android Layout Editor”), you will find that it consists of two values. The very first is the content the thing is advertising media are any project, and the second reason is the title of the application. You can include new values if you wish to rely on them afterwards in code (or perhaps in the Manifest or Layout files). You may also create specific assets using quantifiers. Should you give a – towards the folder’s title, you can include a quantifier towards the title. E.g., you are able to relabel the folder to values-en meaning the information from the folder is an endeavor solely for Android phones with British language triggered. If you don’t give a quantifier, the assets are default. The default assets are utilized if no specific assets for that current system are located. When the project is began, all assets is going to be put together as effectively as you possibly can and put into the package. Also, a reference is going to be produced (known as R) which enables you to definitely connect to the assets in code. As this is merely a tutorial, I won’t concentrate on all the kinds of assets here. You’ll find a lot of assets and quantifiers here.

Finally, it’s time to start coding! Visit the “src” folder. Within the folder, there is a package folder, open the file. You will notice the default code to have an Android Activity:

//some android packages we have to import
import android.application.Activity
import android.os.Bundle

//our activity class (extendes the default activity class)
public class HelloWorldApp stretches Activity Known as once the activity is first produced. */
//the function known as when activity is produced
public void onCreate(Bundle savedInstanceState) From the base class
//load design specified by design.xml

As you can tell, we produce a new activity by stretching the default Android activity class. Only then do we override the default onCreate function, that is known as once the project is produced. Inside, we load our very own layout in the assets as well as call the onCreate purpose of the bottom class. Now let us take particular notice in the layout file. You discover it within the layout folder under assets. Whenever you open it up, it ought to seem like this:

android:layout_width=”fill_parent” android:orientation=”vertical”
xmlns:android=”” />
android:layout_width=”fill_parent” android:text=”@string/hello” />

The thing is the main node is known as LinearLayout. While you you may curently have determined, you will find various kinds of designs:

FrameLayout: All controls (children) are put within the upper left corner.
LinearLayout: All youngsters are situated in vertical/horizontal order.
RelativeLayout: The positions from the youngsters are specified with regards to another children.
TableLayout: The kid elements are put having a power grid.
AbsoluteLayout: The kid elements are situated according to absolute coordinates (in pixel).

After you have selected a layout type, you can include child elements. Within the code given, there’s already a TextView, which is often used to show text on screen. The present submissions are a mention of the an origin defined within the values.xml file. Because you will see, it uses the entire width from the screen, but is just as lengthy as it must, to show the information. We may begin with some small changes. Let us alter the text colour of the TextView to eco-friendly:

android:layout_width=”fill_parent” android:text=”@string/hello”
android:textcolor=”#FF00FF00″ />

Now, launch the project and find out the alterations. Next, let us give a new control known as EditText:

android:layout_width=”fill_parent” android:orientation=”vertical”
xmlns:android=”” />
android:layout_width=”fill_parent” android:textcolor=”#FF0000FF”
android:id=”@+id/et_Text” />
android:textcolor=”#FF00FF00″ android:id=”@+id/lv_View” />

When you want to connect to the controls in code, they have to come with an ID. Next we create some code for that controls.

public void onCreate(Bundle savedInstanceState) design within the resource reference

//obtain the two controls we produced earlier, also using the resource reference and also the id
final TextView tv_View = (TextView)findViewById(
final EditText et_Text = (EditText)findViewById(

//add new KeyListener Callback (to record key input)
et_Text.setOnKeyListener(new OnKeyListener()
whenever a secret is pressed
public boolean onKey(View v, int keyCode, KeyEvent event)
see if there’s
if (event.getAction() == KeyEvent.ACTION_Lower)
see if the best key was pressed
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
add some text towards the textview
tv_View.setText(tv_View.getText() + “, ” +
//and obvious the EditText control
return true

return false


We’ll evaluate the code line by line. To begin with, as before, we load design. Only then do we produce a TextView along with a EditText variable and cargo our interface objects inside them (that is what we want the ID for). Finally, we give a new OnKeyListener towards the EditText control. Within this OnKeyListener, we produce the method onKey, that is known as whenever a secret is pressed, once the control is active. Within the method, we perform two inspections: the very first to be certain that the secret is pressed lower (and never launched), and also the second to specify the important thing (within this situation, the middle key from the D-pad). If both inspections are passed, we add some text from the EditText control towards the TextView, and lastly the written text from the EditText control is erased. Run and try out the application. Great, you produced the first real Android application.

As with all platform, Android features its own design challenges. Always bear in mind that you’re developing for any mobile platform with limited memory, disk space, and processing energy. Therefore, Android instantly kills processes (each application runs in the own process) to help keep the machine responsive. Processes are sorted after importance. The most crucial may be the presently active process, then visible and mentioned service processes. The bottommost kinds of processes in hierarchy are background empty processes. Remember that whenever you create your application, because you wouldn’t want its tactic to be wiped out in the center of something. Also, you should use whatever hardware is made in to the Android phone. But observe that not every phones may have this hardware, and thus not every might have the ability to run your application.

There you have it with this tutorial. Hopefully, you understood the fundamentals of Android development. As this is my first article on CodeProject, I’d really appreciate feedback!