Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers.
Speciality of android
- open source
- Larger developer and community research
- Increased marketing
- Inter app integration
- Reduced cost of development
- Higher Success Ratio
- Rich development environment
Android IDEs
There are so many Technologies are available to develop android applications, the familiar technologies, but tools we are using now is
- Android Studio
- Eclips IDE
Android SDK
The Android SDK (software development kit) is a set of development tools used to develop applications for Android platform.
For Example Syntax :
<uses-sdk android:minSdkVersion=”integer”
android:targetSdkVersion=”integer”
android:maxSdkVersion=”integer” />
What is API Level?
API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform.
The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of:
- A core set of packages and classes
- A set of XML elements and attributes for declaring a manifest file
- A set of XML elements and attributes for declaring and accessing resources
- A set of Intents
- A set of permissions that applications can request, as well as permission enforcements included in the system
Android Libraries
This category encompasses those Java-based libraries that are specific to Android development. Examples of libraries in this category include the application framework libraries in addition to those that facilitate user interface building, graphics drawing and database access. A summary of some key core Android libraries available to the Android developer is as follows −
android.app − Provides access to the application model and is the cornerstone of all Android applications.
android.content − Facilitates content access, publishing and messaging between applications and application components.
android.database − Used to access data published by content providers and includes SQLite database management classes.
android.opengl − A Java interface to the OpenGL ES 3D graphics rendering API.
android.os − Provides applications with access to standard operating system services including messages, system services and inter-process communication.
android.text − Used to render and manipulate text on a device display.
android.view − The fundamental building blocks of application user interfaces.
android.widget − A rich collection of pre-built user interface components such as buttons, labels, list views, layout managers, radio buttons etc.
android.webkit − A set of classes intended to allow web-browsing capabilities to be built into applications.
Having covered the Java-based core libraries in the Android runtime, it is now time to turn our attention to the C/C++ based libraries contained in this layer of the Android software stack.
Activities
An activity represents a single screen with a user interface,in-short Activity performs actions on the screen. If an application has more than one activity, then one of them should be marked as the activity that is presented when the application is launched.
For Example :
public class MainActivity extends Activity {
}
Create Android Application
The first step is to create a simple Android Application using Android studio. Follow the option File -> New -> New Project . Now name your application as HelloWorld , select Company domain , package name and click next.
In next page select select SDKs level , most commonly used SDKs level is API 15 by default because it will support upto 94{1d6e369f27b3b55fac77a13f30e13d2b04ce9713b9295394d4a423074fd2099f} of mobile devices. click next and select the Activity you want , here select activity_name , layout_name that you are going to use and click finish.
Anatomy of Android Application
Before you run your app, you should be aware of a few directories and files in the Android project −
1. 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.
2. gen
This contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file.
3. bin
This folder contains the Android package files .apk built by the ADT during the build process and everything else needed to run an Android application.
4. res/drawable-hdpi
This is a directory for drawable objects that are designed for high-density screens.
5. res/layout
This is a directory for files that define your app’s user interface.
6. res/values
This is a directory for other various XML files that contain a collection of resources, such as strings and colours definitions.
7. AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.
Main Activity .java
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;
}
}
The Manifest File
Whatever component you develop as a part of your application, you must declare all its components in a manifest.xml which resides at the root of the application project directory. This file works as an interface between Android OS and your application, so if you do not declare your component in this file, then it will not be considered by the OS.
For Example :
<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>
The String File
The strings.xml file is located in the res/values folder and it contains all the text that your application uses. For example, the names of buttons, labels, default text, and similar types of strings go into this file. This file is responsible for their textual content.
For Example :
<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 Layout File
The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application when building its interface. You will modify this file very frequently to change the layout of your application.
For Example :
<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>