Monday, August 15, 2016

How to create simple Android App?

What is Android?

Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies.

Android offers a unified approach to application development for mobile devices which means developers need only develop for Android, and their applications should be able to run on different devices powered by Android.

The source code for Android is available under free and open source software licenses. Google publishes most of the code under the Apache License version 2.0 and the rest, Linux kernel changes, under the GNU General Public License version 2.

Why Android ?

  • Open source
  • Larger developer and community reach
  • Increased marketing
  • Inter app integration
  • Reduce cost of development
  • Higher success ratio
  • Rich development envirnment

How to built android app?

Tools required for building app:
  • Java JDK5 or later version
  • Android SDK
  • Java Runtime Environment (JRE) 6
  • Android Studio
Create Android Application

The first step is to create a simple Android Application using Android Studio. Follow the option File -> New project ->Configure your new project -> selct factor your application is run on -> add activity ->Customise your activity -> and finally select finish wizard from the wizard list. Now name your application as HelloWorld using the wizard window as follows:


SELECT START A NEW APPLICATION PROJECT


ENTER AN APPLICATION NAME




SELECT MIN-SDK VERSION

If all things goes right following screen will appear





Before moving further there few directory to keep in mind

build: This contains the auto generated file which are as Aidl,Build configuration, and R(R.JAVA)

Libs: This is a directory to add the libraries to develop the android applications

src: This contains the .java source files for your project. By default, it includes an MainActivity.java source file having an activity class that runs when your app is launched using the app icon.

res: This is a directory,which is having drawable,layout,values,and android manifest file

res/layout: This is a directory for files that define your app's user interface.

AndroidManifest.xml: This is the manifest file which describes the fundamental characteristics of the app and defines each of its components

Main Activity file

This is default code generated by application.


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;
   }
}



Manifest File


<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>



String file

As default this file will look like this


<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>


Layout file

By default this file will look like this

This is an example of simple RelativeLayout which we will study in a separate chapter. The TextView is an Android control used to build the GUI and it have various attributes like android:layout_width, android:layout_height etc which are being used to set its width and height etc. The @string refers to the strings.xml file located in the res/values folder. Hence, @string/hello_world refers to the hello string defined in the strings.xml fi le, which is "Hello World!”.



<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>


Other interesting things?

Features of Android

Feature
Description
Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
Storage
SQLite, a lightweight relational database, is used for data storage purposes
Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP
Web browser
Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript engine supporting HTML5 and CSS3.
Multi-tasking
User can jump from one task to another and same time various application can run simultaneously.
GCM
Google Cloud Messaging (GCM) is a service that lets developers send short message data to their users on Android devices, without needing a proprietary sync solution.
Multi-Language
Supports single direction and bi-directional text.

No comments: