12-11-2016, 10:58 AM
1476879459-Android.docx (Size: 262 KB / Downloads: 7)
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 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.
The first Android-powered phone was sold in October 2008.
Since April 2009, Android versions have been developed under a codename and released according to alphabetical order: Cupcake (1.5), Donut (1.6), Eclair (2.0–2.1), Froyo (2.2–2.2.3), Gingerbread (2.3–2.3.7), Honeycomb (3.0–3.2.6), Ice Cream Sandwich (4.0–4.0.4), Jelly Bean (4.1–4.3), and KitKat (4.4). On 3 September 2013 Google announced that 1 billion activated devices now use the Android OS worldwide. The most recent major Android update was Jelly Bean 4.3, which was released on commercial devices on 24 July 2013
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.
At the bottom of the layers is Linux - Linux 2.6 with approximately 115 patches. This provides basic system functionality like process management, memory management, device management 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.
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.
Android Runtime
This is the third section of the architecture and available on the second layer from the bottom. 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.
Application Framework
The Application Framework layer provides many higher-level services to applications in the form of Java classes. Application developers are allowed to make use of these services in their applications.
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.
Android Application Components
In this second article on Android key concepts in the Android development tutorial series, we will analyze the various components by which an Android Application is made of. That is, the Android Application Components.
There are mainly five types of components that are used to build an application. Actually these are some objects defined in the Android SDK and provides different methods by which an application can behave. As a developer we need only to call and extend these already defined classes to use in our application.
These are the main Android Application Components:
• Activities
• Services
• Content Providers
• Broadcast Receivers
• Intents
I’m not going to give a full explanation on each of these components. You will learn how to use these Android application components to build applications later, when we start actual development. Now I’m giving you brief descriptions of each terms to make you familiar with the basic concepts.
Activities
Activity is an individual user interface screen in an Android application where visual elements called Views (also known as widgets) can be placed and the user can perform various actions by interacting with it. Consider the figure. The whole window gives the user an interface to interact with and therefore this complete screen makes an Activity. The controls placed in the window allows the user to perform certain actions and are called Views or Widgets. In this example, there are five widgets, they are – TextView, EditText AnalogClock and two Buttons. The widgets in an Activity can be created in two different ways, by pure java code and by adding XML code to define the UI. An application can have more than one Activity and each Activity operates independently, but can be linked to one another and each Activity you create must be defined in your application’s manifest file. Each Activity in android will be subclass of Activity class defined in Android SDK.
2. Services
A service is an Android application component that runs in background and has no visual UI. Services are used to perform the processing parts of your application in the background. While the user is working on the foreground UI, services can be used to handle the processes that need to be done in the background. A service can be started by another Android application components such as an activity or other services and it will continue to run in the background even after the user switches to another application. Thus services are less likely to be destroyed by Android system to free resources, than Activities.
One typical example for the use of services is a music player application. We can use an activity to select a music track from the SD card and to play it. When it starts playing, the user is able to open another applications and the music plays in the background. This can be made possible only by the use of Android Services. The Activity that chooses the music track actually invokes a service that works in the background. Then it will continue playing in the background even after the frontend activity gets destroyed. All Android services are implemented as a subclass of Service class defined in Android SDK. There are two types of services in Android.
They are:
Unbound Services
Its a type of service which is not bounded to any components. Once started, it will run in the background even after the component that started the service gets killed. It can be run in the background indefinitely and should stop by itself after the operation its intended to carry out is completed.
Bound Services
Its bound to other components and runs only till the component to which it is bounded runs.
3. Content Providers
Content providers in Android provides a flexible way to make data available across applications. Suppose you are creating any type of data in your application (For example consider you are creating a to do list in your application, then the list of things is a data) and you are storing it at any storage location, it may be in the data base, file system or in any online storage space. Then through content providers other applications are able to query, access or even modify the data you’ve created, as long as your content provider allows it. In a similar way you can access the data that other utilities have created, by using content providers. Example for content provider in Android is the contacts database. The Content provider of contacts database allows other applications to query, read, modify, and write the contacts info. Android comes with several other built in Content providers that we can use in our application. All content providers are implemented as a subclass of ContentProvider class which is defined in Android SDK.
4. Broadcast Receivers
Broadcast receivers are one of Android application components that is used to receive messages that are broadcasted by the Android system or other Android applications. There are many broadcasts that are initiated by the Android system itself and other applications can receive by using Broadcast receiver. Examples of broadcasts initiated by the system are:
1. Warning that the battery is getting low
2. Screen turned off
3. Change of time zone
4. The camera has been used to take a picture
While programming, we can use Broadcast receivers to receive these broadcasted messages and behave accordingly. Applications can also initiate broadcasts. We can initiate as many broadcasts as we want and there’s no limits for that.
5. Intents
Actually intents are not one of Android application components, instead it is the component activating mechanism in Android. It constitutes the core message system in Android and defines a message to activate a particular component. For example, if you want to invoke a new activity from your current activity, you need to fire an intent specifying the new activity. And if you want to start other application from your activity, then also you need to fire an intent. That is by firing an intent, you are telling the Android system to make something happen.
There are two types of Intents in Android:
Explicit Intents:
In explicit Intent, we are highly specific. We specify which activity should get active on receiving the intent. These are usually used for application’s internal communications.
Implicit Intents:
In implicit Intent we are sending a message to the Android system to find a suitable Activity that can respond to the intent. For example, to send an e-mail, we can use an intent. We will also specify the data to be operated on, with the intent. On receiving the Intent, Android system will invoke an Activity which is able to send e-mail messages with the data that we specified. If there is more than one activity is capable of receiving the Intent, the system presents a chooser to the user so that he can select which Activity/Application should handle it.
AndroidManifest.xml
Manifest file for an android application is a resource file which contains all the details needed by the android system about the application. It is a key file that works as a bridge between the android developer and the android platform. It helps the developer to pass on functionality and requirements of our application to Android. This is an xml file which must be named as AndroidManifest.xml and placed at application root. Every Android app must have AndroidManifest.xml file.
Among other things, the manifest does the following:
• It names the Java package for the application. The package name serves as a unique identifier for the application.
• It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
• It determines which processes will host application components.
• It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
• It also declares the permissions that others are required to have in order to interact with the application's components.
• It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
• It declares the minimum level of the Android API that the application requires.
• It lists the libraries that the application must be linked against.
• onCreate: This is where the UI is defined. This method is called only the first time that the activity instance is launched and when it has been dropped by the system
• onPause: User is leaving the activity, so any changes made, should be committed
• onStart: Class members are still alive, as the class was just stopped, so the memory costy resources that have been released, should be re-initialized at this state.
• onDestory: Activity is finishing or being destroyed by the system.
• Entrire Lifetime:
- Between the onCreate and onDestroy events
Visible Lifetime
- Between the onStart and onStop events
Foreground Lifetime
- Between the onResume and on Pause events. An application might pass frequently from these stages, so no heavey load should be performed during these transitions.
• Status transitions:
1. Activity at the top of the stack is active or running
2. Activity lost focus but is still visible, when is paused. Can be killed by the system in extreme low memory situations.
(it maintains all state and member information)
3. Activity has been completely obscured by another activity, then its stopped. It is no longer visible to the user so its
window is hidden and it will often be killed by the system when memory is needed elsewhere.
(it maintains all state and member information)
4. While an activity being in paused or stopped state, it might be dropped by the system, in order to release memory. When viewed again, it has to be completely restarted from its previous state.
• Coordinating activities:
- Activity A’s onPause() method executes.
- Activity B’s onCreate(), onStart(), and onResume() methods execute in sequence. (Activity B now has user focus.)
- Then, if Activity A is no longer visible on screen, its onStop() method executes.
• Note that it is important to save persistent data in onPause() instead of onSaveInstanceState(Bundle) because the latter is not part of the lifecycle callbacks. This method is called before placing the activity in such a background state, allowing you to save away any dynamic instance state in your activity into the given Bundle, which will be passed to the new object through the onCreate(Bundle) method, if the activity needs to be re-created.
Service Life-cycle
• onCreate: service is instantiated and setup
• onStartCommand(Intent, int, int): service receives a call via startService.
• onDestroy: when an activity calls stopService, or the service itself calls stopSelf, or the system decides to destroy the service.
• * Using binding, an Activity can connect to a Service and make direct calls back to the service. This is another method of using services, which cannot be covered in this post. This method of starting and accessing a Service affects the life cycle of the Service.
• Two modes of operation depending on the value returned by the onStartCommand method:
- constant START_STICKY is used for services that are explicitly started and stopped as needed.
- constants START_NOT_STICKY or START_REDELIVER_INTENT are used for services that should only remain running while processing any commands sent to them.
• That’s all for now. I have also attached the life-cycle describing diagrams from Android SDK documentation.