Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Android Development: How to Develop an Android App

This article covers the basics about how to develop an Android APP. Android, as we all know is an open source software built for use in Smartphone or a Tablet Computer.

What is programming in Android all about and what are the advantages?

Programming in Android is primarily based around another programming language Java. If you have a basic understanding of Java you can easily play around making applications in Android and using them in your mobile or computer. The advantages of programming in Android are listed below:

  • Being open source, Android offers freedom for developers to edit the codes using any editor and deploy it in any mobile device which supports Android OS.
  • It is free and does not need you to install any heavy and costly software’s in your system.
  • You can distribute your app through a number of distribution stores (e.g. Google Playstore, Amazon Playstore, etc.)
  • Anyone with knowledge of Java can make an Android App. You don’t need to learn anything new.

Prerequisites for Android programming (Tools)

Prior starting programming for Android, you need to ensure that you have following tools in place in your local system -

  1. Java Development Kit (JDK)
  2. Android SDK
  3. Eclipse IDE (Popular tool for writing Java Programs)
  4. Android Development tools and Eclipse Plug-in

In order to have the system ready with the above software’s, please follow these steps.

Step1 - Setup Java Development Environment

Check your system if it does not have JDK installed already, you may need to install JDK from the Oracle website. Download the latest version of Java Development Kit (JDK). Once you the download is complete, you can run the setup from the downloaded files and follow the instructions as given in the downloaded files. Once installation is complete, set the Windows Environment variables (PATH and JAVA_HOME) to appropriate program files location where java and javac executable files are located.

Note: For Windows OS, you can find the Environment variables in System Properties->Advanced System Settings->Environment Variables->System Values->Select PATH/JAVA_HOME value and update with the java and javac folder locations.

For Linux OS, you will need to manually run add the folder paths using Shell Script in the .cshrc file.

Step 2 - Download the install Android SDK and Eclipse

Download the latest version of Android SDK from Android website. In this page, you will see the link “Get the SDK”, click on that link, click on the download link, accept the agreement and select the download as per your OS. when download is complete, extract the archive onto a development folder where you intend to store all you program files. Now open the adt-bundle-/eclipse folder and launch Eclipse. In order to confirm that you have installed the software

Note: In case you encounter any issue while downloading the archive or locating the correct link, check for the correct version of the SDK for your system in the Android website (http://developer.android.com).

Programming in Android:

Step 1 - Creating the first Android program in Eclipse:

Okay, time now to start with actual android programming. Prior starting actual programming, it would be wise to check you have all necessary components as mentioned in the previous section.

follow these steps –

  1. In the extracted ADT folder, navigate to the /eclipse folder and run the eclipse.exe program. During the first run, you will be prompted to select a workspace (You can chose to hide this option by clicking on the option – Do not show this prompt in startup).
  2. Once Eclipse is open, you will see a default layout (first time) with options of trying out learning tutorials or directly creating a new android application.
  3. Click on New Android Application and you will see a dialog which requires you to enter relevant details like application name, project name and package name. Enter the relevant Application Name in the Application Name text field.
    You need not make any other changes or modify any other values in the other parameters since this is the first app we are creating. For more information on what each parameter means, you can rollover your mouse over theicon.
    Note: The Package Name will usually show up a warning symbol, since apps created with com.example URL cannot be published on the Google Play store. In case you want your app to be published on Google Play Store you need to own your own domain for app and you can put the reverse domain URL in the Package Name parameter.
  4. Click Next. In the Next screen leave the defaults as is and click on Next.
  5. In the Configure Launcher icon, you can select attributes for your launcher icon as per your preference. You could also chose to leave it as is, if you haven’t created an icon previously. Click Next.
  6. On the Create Activity Screen, leave the default “Blank Activity” as is and Click Next.
  7. In the Blank Activity Screen you see the details of the type of navigation for this activity. You can choose to leave this to defaults or chose a particular type in case you want specific activity on the app screen.
  8. Click on Finish.
  9. In few seconds, you will be shown a New Android App folder with files created for you to start building your app. In the left hand side of the new android app project file, you will see the folder structure for the new app project and on the left hand side, you will see the layout xml file and the java class file for the app.

Step 2 – Knowing the basics of the Android Application project file

Before you start adding elements or start writing raw code in your xml or java class file, you need to know the relevance of the directories and files within the project file.

About folders -

In the right hand side, you will see the various folders for the project. The relevance of the folders are explained below :-

Src – Contains all the java source files.
Gen – Contains all generated or compiled files. These files cannot be modified.
Android x.x, Android Private libraries – contains all android files useful for compiling your app.
Assets – stores the assets for your app.
Bin – stores all binary files for your app. These files are important to run your application.
Res- stores all the resource files like icons, interface/drawable objects and layouts for the app.
AndroidManifest.xml – Manifest file containing fundamental details of your app and each component. The code view of the AndroidManifest file will look something like this:-

<?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.demoapp01"
      android:versionCode="1"
      android:versionName="1.0" >
   
      <uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="18" />
   
      <application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" >
          <activity
              android:name="com.example.demoapp01.MainActivity"
              android:label="@string/app_name" >
              <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
   
                  <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
          </activity>
      </application>
   
  </manifest>

About Android Application Project files

In the newly created app project file, you will see 2 files open in Eclipse; The activity_main.xml and the MainActivity.java file.

MainActivity.java is the java file. This file stores all the code for your app and is the file which gets converted into the executable in order for your application to run. The default code of the MainActivity.java file is shown below:

 package com.example.demoapp01;
   
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
   
  public class MainActivity extends Activity {
   
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
   }

Activity_main.xml is the main layout file for the app and it has a default graphical view and a XML view.

In the Activity_main.xml when you switch to the graphical view, you will see the app view in the right hand side and the Palette with the options on the left hand side.Using the elements in the Palette, you can add form widgets, text field, layout items and so on, in your App.

In the XML view, you will see the code view of the app. The code for the above app is shown below –

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" >
   
      <TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" />
   
  </RelativeLayout>

Whenever you add an element from palette, you will see the XML code being updated to reflect the new element. An example of addition of a button is shown below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" >
   
      <TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" />
   
      <Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView1"
          android:layout_below="@+id/textView1"
          android:layout_marginLeft="50dp"
          android:layout_marginTop="88dp"
          android:text="Button"
          tools:ignore="HardcodedText" />
   
  </RelativeLayout>
  When you add a text field on the layout, you see the updated code showing <Edit Text> values.
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".MainActivity" >
   
      <TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" />
   
      <EditText
          android:id="@+id/editText1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/textView1"
          android:layout_below="@+id/textView1"
          android:layout_marginLeft="20dp"
          android:layout_marginTop="17dp"
          android:ems="10" >
          <requestFocus />
      </EditText>
   
  </RelativeLayout>

In addition to the above files, you also have the resource files (Strings, Styles and Dimension files) which resides in the /res/values folder.

Strings.xml - The strings.xml contains all the text used by the application and its components. The code view of the Strings.xml is in the following format-

<?xml version="1.0" encoding="utf-8"?>
 <resources>
      <string name="app_name">DemoApp01</string>
      <string name="action_settings">Settings</string>
      <string name="hello_world">Hello world!</string>
   
  </resources>

As and when you add more items which have text in it, you will see new additions in the strings.xml file.

Styles.xml – This file contains the layout theme references within it.

<br clear="all">   <resources>
      
      <style name="AppBaseTheme" parent="android:Theme.Light">
      </style>
   
      <!-- Application theme. -->
      <style name="AppTheme" parent="AppBaseTheme">
      </style>
   
  </resources>

Dimens.xml – contains the pre-defined screen margins for the app as per Android Design guidelines. The code view of the dimens.xml is as shown below.

<resources>
   
      <dimen name="activity_horizontal_margin">16dp</dimen>
      <dimen name="activity_vertical_margin">16dp</dimen>
   
  </resources>

Project. properties - For each project app, you work on you will have the properties for the project listed out in a text file called as project. properties. This is a auto-generated file created by Android software for your app and should not be modified. Modifying this will create problems in your app. The code view of the project. properties is shown below –

Here you will be shown some commands .. just have alook at that ..

Step 3 – Running your App

Once you have completed building your app, you will need to build it in order to view the app. For building the app, click on the Run button in the Eclipse toolbar Window. You will receive a dialog window requiring you to select the type of Application. Select Android Application and Click on OK. When the mobile device is connected to your computer, then you will see the app running on your mobile device. If your mobile device is not connected, then it will display an Emulator Window showing your App running.

Once your app is built, you will notice the presence of generated files in the gen folder. The R file is the automatically generated file of the built application from the source MainActivity.java file. The code of the R.java file looks something like this:-

  package com.example.demoapp01;
   
  public final class R {
      public static final class attr {
      }
      public static final class dimen {
          public static final int activity_horizontal_margin=0x7f040000;
          public static final int activity_vertical_margin=0x7f040001;
      }
      public static final class drawable {
          public static final int ic_launcher=0x7f020000;
      }
      public static final class id {
          public static final int action_settings=0x7f080002;
          public static final int button1=0x7f080001;
          public static final int textView1=0x7f080000;
      }
      public static final class layout {
          public static final int activity_main=0x7f030000;
      }
      public static final class menu {
          public static final int main=0x7f070000;
      }
      public static final class string {
          public static final int action_settings=0x7f050001;
          public static final int app_name=0x7f050000;
          public static final int hello_world=0x7f050002;
      }
      public static final class style {
          /** 
          Base application theme, dependent on API level. This theme is replaced
          by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
      
   
              Theme customizations available in newer API levels can go in
              res/values-vXX/styles.xml, while customizations related to
              backward-compatibility can go here.
          
   
          Base application theme for API 11+. This theme completely replaces
          AppBaseTheme from res/values/styles.xml on API 11+ devices.
      
   API 11 theme customizations can go here. 
   
          Base application theme for API 14+. This theme completely replaces
          AppBaseTheme from BOTH res/values/styles.xml and
          res/values-v11/styles.xml on API 14+ devices.
      
   API 14 theme customizations can go here. 
           */
          public static final int AppBaseTheme=0x7f060000;
          public static final int AppTheme=0x7f060001;
      }
  }

Conclusion:

With this, we conclude the tutorial on the basics of programming in Android. Programming in Android is always fun and gives the developer the flexibility and freedom to code and deploy in their own way.



Computer system engineer who has 4 year of experience in the field our web-development ,FPGA, and java programming.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login