Saturday, 31 December 2016

Android Application Components

Android's application framework lets you create rich and innovative apps using a set of reusable components. This section explains how you can build the components that define the building blocks of your app and how to connect them together using intents.

Application components are the essential building blocks of an Android application. These components are loosely coupled by the application manifest file AndroidManifest.xml that describes each component of the application and how they interact.
There are following four main components that can be used within an Android application −
1. ActivitiesThey dictate the UI and handle the user interaction to the smart phone screen.
2. Services- They handle background processing associated with an application.
3. Broadcast Receivers-   They handle communication between Android OS and applications.
4. Content Providers- They handle data and database management issues.

There are some more important components that are used in Android Application-
1. Intents and Intent Filter
2. Loaders
3. Processes and Threads
4. Fragments
5. App Widgets
6. Views and View Groups

I will explain all of these one by one in next blogs.Now have look on Main Android Application Components-

Activities

An activity represents a single screen with a user interface,in-short Activity performs actions on the screen. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. 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.
An activity is implemented as a subclass of Activity class as follows −
public class MainActivity extends Activity {
}

Services

A service is a component that runs in the background to perform long-running operations. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity.
A service is implemented as a subclass of Service class as follows −
public class MyService extends Service {
}

Broadcast Receivers

Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For example, applications can also initiate broadcasts to let other applications know that some data has been downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this communication and will initiate appropriate action.
A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each message is broadcaster as an Intent object.
public class MyReceiver  extends  BroadcastReceiver {
   public void onReceive(context,intent){}
}

Content Providers

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. The data may be stored in the file system, the database or somewhere else entirely.
A content provider is implemented as a subclass of ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.
public class MyContentProvider extends  ContentProvider {
   public void onCreate(){}
}



Wednesday, 28 December 2016

Android Platform Architecture

Android is an open source, Linux-based software stack created for a wide array of devices and form factors. The following diagram shows the major components of the Android platform.
                                     
Android operating system is a stack of software components which is roughly divided into five sections and four main layers as shown below in the architecture diagram.

       Android Architecture

Linux kernel
The foundation of the Android platform is the Linux kernel. This provides a level of abstraction between the device hardware and it contains all the essential hardware drivers like camera, keypad, display etc. Also, the kernel handles all the things that Linux is really good at such as networking and a vast array of device drivers, which take the pain out of interfacing to peripheral hardware.For example, the Android Runtime (ART) relies on the Linux kernel for underlying functionalities such as threading and low-level memory management.
Using a Linux kernel allows Android to take advantage of key security features and allows device manufacturers to develop hardware drivers for a well-known kernel.

Hardware Abstraction Layer(HAL)

The hardware abstraction layer (HAL) provides standard interfaces that expose device hardware capabilities to the higher-level Java API framework. The HAL consists of multiple library modules, each of which implements an interface for a specific type of hardware component, such as the camera or bluetooth module. When a framework API makes a call to access device hardware, the Android system loads the library module for that hardware component.

Android Libraries/Native C/C++ Libraries

On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit, well known library libc, SQLite database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc.Many core Android system components and services, such as ART and HAL, are built from native code that require native libraries written in C and C++. The Android platform provides Java framework APIs to expose the functionality of some of these native libraries to apps. For example, you can access OpenGL ES through the Android framework’s Java OpenGL API to add support for drawing and manipulating 2D and 3D graphics in your app.
If you are developing an app that requires C or C++ code, you can use the Android NDK to access some of these native platform libraries directly from your native code.

Android Runtime

For devices running Android version 5.0 (API level 21) or higher, each app runs in its own process and with its own instance of the Android Runtime (ART). ART is written to run multiple virtual machines on low-memory devices by executing DEX files, a bytecode format designed specially for Android that's optimized for minimal memory footprint. Build toolchains, such as Jack, compile Java sources into DEX bytecode, which can run on the Android platform.
Some of the major features of ART include the following:
  • Ahead-of-time (AOT) and just-in-time (JIT) compilation
  • Optimized garbage collection (GC)
  • Better debugging support, including a dedicated sampling profiler, detailed diagnostic exceptions and crash reporting, and the ability to set watchpoints to monitor specific fields
Prior to Android version 5.0 (API level 21), Dalvik was the Android runtime. If your app runs well on ART, then it should work on Dalvik as well, but the reverse may not be true.This section provides a key component called Dalvik Virtual Machine which is a kind of Java Virtual Machine specially designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-threading, which is intrinsic in the Java language. The Dalvik VM enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable Android application developers to write Android applications using standard Java programming language.
Android also includes a set of core runtime libraries that provide most of the functionality of the Java programming language, including some Java 8 language features, that the Java API framework uses.
Java API/Application Framework

The entire feature-set of the Android OS is available to you through APIs written in the Java language. These APIs form the building blocks you need to create Android apps by simplifying the reuse of core, modular system components and services, which include the following:
  • A rich and extensible View System you can use to build an app’s UI, including lists, grids, text boxes, buttons, and even an embeddable web browser
  • Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
  • Notification Manager that enables all apps to display custom alerts in the status bar
  • An Activity Manager that manages the lifecycle of apps and provides a common navigation back stack
  • Content Providers that enable apps to access data from other apps, such as the Contacts app, or to share their own data.
Developers have full access to the same framework APIs that Android system apps use.
The Android framework includes the following key services −
  1. Activity Manager − Controls all aspects of the application lifecycle and activity stack.
  2. Content Providers − Allows applications to publish and share data with other applications.
  3. Resource Manager − Provides access to non-code embedded resources such as strings, color settings and user interface layouts.
  4. Notifications Manager − Allows applications to display alerts and notifications to the user.
  5. View System − An extensible set of views used to create application user interfaces.

Applications

You will find all the Android application at the top layer. You will write your application to be installed on this layer only. Examples of such applications are Contacts Books, Browser, Games etc.

Tuesday, 27 December 2016

Android Environment Setup

First of all your should know that Android Mobile Application Development can be done on any operating system like Mac OS,Windows,Ubuntu etc.

Following is the list of software's you will need before you start your Android application programming-
  1. Java JDK5 or later version
  2. Android Studio
Setting up Java Development Kit(JDK)
 
First Download most updated JDK version from following website-


Here your will also find the instructions to set up JDK. When you open the website screen will be like the below-


Android IDE's

There are so many IDE's available to develop Android Mobile Application but now Google has launched it's officially IDE know as Android Studio.So it is better to work on this you can download Android Studio from following link-  https://developer.android.com/studio/index.html

 

Android Introduction

Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Initially Android was developed by Andy Rubin ,Android name is after himself only.After that his company was acquired by Google and then Android was developed under the Open Handset Alliance, led by Google, and other companies.
The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September 2008.
On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of improving the user interface, both in terms of functionality and performance.
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 should we use Android-


This image explain itself that Android is an open source that makes it superior than other mobile development platforms.Android has larger base of audience and rich user interface.
Versions of Android-