How To Develop An Android App

How To Develop an Android App

How To Develop an Android App this sentence is easy to listen but hard for work on it in this tutorial i just explain that how to develop an android app which is very simple app but it is very necessary to learn because through it you can develop an advanced android apps . Now we start the practical programming with Android Framework. Before you begin writing your first program by using Android SDK, you need to ensure that you have set up your Android development environment appropriately as clarified in Android  Environment Set-up – tutorial exercise.So let we continue to write a very simple and helpful Android Application which will print “Hello World!”

how to develop an android app

The first step how to make an app using Eclipse IDE. As we start from beginners to advanced so this example is for beginners .Follow the path option File -> New -> Project and then move the cursor on Android New Application  wizard from the wizard list and Select it. Now name your application as you want we named it as HelloWorld using the wizard window as follows:

how to develop an android app

 

 

Now Follow the above example and set all the entries to default until we reached the final step. Is Your Project Successfully Created? If Yes then follow the steps

how to develop an android app

Anatomy of Android Application

Don’t run  application right now. you should know a few folders and files in the Android Project

how to develop an android app

 

File And Folder Description

1. src

This contains the .java source files for your task/project. As by default, it incorporates a MainActivity.java source document having an activity class that runs when your application is propelled utilizing the application icon.

2. gen

This contains the .R document/file, a compiler-generator file that references all the resources found in your task. You should not change this document.

3. bin

This organizer contains the Android package documents .apk worked by the ADT during the build procedure and everything else expected to run an Android application.

4. res/drawable-hdpi

This is a folder for drawable items that are intended for high-thickness screens.

5. res/layout

This is an index for records that characterize your application’s UI.

6. res/values

This is a folder for different XML files that contain a gathering of resources, for example, strings, colors and hues definitions.

7. AndroidManifest.xml

This is the manifest document which shows the basic qualities of the application and characterizes each of its parts.

Now we come to our next process

  • The Main Activity File

The Main Activity Program is a Java file MainActivity. java. This is the genuine application file which in the end gets transformed into a Dalvik executable and works your application. Following is the default code made by the application wizard only for Hello World! program –

package com.example.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;

public class MainActivity extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
   }
   
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
   }
}

 

right here, R.layout.activity_main refers to the activity_main.xml file positioned within the res/layout folder. The onCreate() method is one among many techniques and methods that are figured when an activity is loaded.

  • The Manifest File

Whatever segment you develop as a piece of your application, you should declare every one of its parts in a manifest.xml which resides at the root of the application project folder. This document fills in as an interface between Android OS and your application, so in the event that you don’t declare your component in this record, then it won’t be considered by the OS. For instance, a default manifest document will look like as file which written below –

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.helloworld"
   android:versionCode="1"
   android:versionName="1.0" >
   
   <uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="22" />
   
   <application
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@style/AppTheme" >
       
       <activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" >
       
          <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER"/>
          </intent-filter>
       
       </activity>
       
   </application>
</manifest>

 

Here <application>…</application> labels enclosed the parts identified with the application. Attribute android:icon will indicate the application symbol accessible under res/drawable-hdpi. The application users the picture named ic_launcher.png situated in the drawable directory

The <activity> tag is utilized to determine an activity and android:name attribute indicates the completely qualified class name of the Activity subclass and the android:label attribute indicates a string to use as the mark for the activity. You can indicate various exercises utilizing <activity> labels/tags.

The action for the intent filter is called android.intent.action.MAIN to show that this activity serves as the passage point for the application. The category for the intent-filter is called android.intent.category.LAUNCHER to show that the application can be run from the device launcher icon.

The @string alludes to the strings.xml document/file clarified underneath. Consequently, @string/app_name refers to the app_name string characterized in the strings.xml file, which is “HelloWorld”. Comparative way, different strings get populated in the application.

Following is the rundown of tags which you will use in your manifest file to indicate different Android application segments:

  • <activity> elements for activities
  • <service> components for services
  • <receiver> components for communicate collectors/broadcast receivers
  • <provider> elements for content providers.

The String File

The strings.xml document is situated in the res/values directory and it contains all the content that your application uses. For instance, the names of buttons, marks/labels, default content/text, and comparative sorts of strings go into this file. This document is in charge of their textual substance. For instance, a default strings file is as the following file

<resources>
   <string name="app_name">HelloWorld</string>
   <string name="hello_world">Hello world!</string>
   <string name="menu_settings">Settings</string>
   <string name="title_activity_main">MainActivity</string>
</resources>

 

The R File

The gen/com.example.helloworld/R.java file is the glue between the activity Java files like MainActivity.java and the assets like strings.xml. It is a consequently created file and you should not adjust the content of the R.java record. The example of R.java file is given below

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.example.helloworld;

public final class R {
   public static final class attr {
   }
   
   public static final class dimen {
      public static final int padding_large=0x7f040002;
      public static final int padding_medium=0x7f040001;
      public static final int padding_small=0x7f040000;
   }
   
   public static final class drawable {
      public static final int ic_action_search=0x7f020000;
      public static final int ic_launcher=0x7f020001;
   }
   
   public static final class id {
      public static final int menu_settings=0x7f080000;
   }
   
   public static final class layout {
      public static final int activity_main=0x7f030000;
   }
   
   public static final class menu {
      public static final int activity_main=0x7f070000;
   }
   
   public static final class string {
      public static final int app_name=0x7f050000;
      public static final int hello_world=0x7f050001;
      public static final int menu_settings=0x7f050002;
      public static final int title_activity_main=0x7f050003;
   }
   
   public static final class style {
      public static final int AppTheme=0x7f060000;
   }
}

 

 

The Layout File

The activity_main.xml is a layout document accessible in res/format catalog, that is referenced by your application when building its interface. You will adjust this file oftentimes to change the layout of your application. For your “Hello World!” application the file have the following layout.

<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" >
   
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:padding="@dimen/padding_medium"
      android:text="@string/hello_world"
      tools:context=".MainActivity" />
      
</RelativeLayout>

 

This is a case of basic RelativeLayout which we will think about in a different section. The TextView is an Android control used to manufacture the GUI and it has different attributes like android:layout_width, android:layout_height and so forth which are being utilized to set its width and height and so forth. The @string alludes to the strings.xml file situated in the res/values directory. Consequently, @string/andro_development refers to the andro string characterized in the strings.xml file, which is “Hello World!”

Running The Application

Now It’s time to run our application which is Andro Development! I assume you had made your AVD while doing Android Environment Set-up. Now you have to run the application from Eclipse, open one of your project activity files and just click on the Run symbol from the toolbar. Eclipse installs the application on your AVD and begins it and if all is well with your set-up and application, it will show the following Emulator window

how to develop an android app

You Have simply developed your 1st ever Android Application. Congratulations!. As this tutorial (how to develop an app) is simply for beginners if you would like to become an excellent Android Developer you have got to follow all the tutorials step by step. Good Luck!