Saturday 8 October 2016

ANDROID


                          ANDROID


                      ABSTRACT


Android is an operating system for Mobile phones. Lot of advances can be seen these days in the field of smartphones. As the number of users is increasing day by day, facilities are also increasing. Starting with simple phones which were made just to make and receive calls. Now we have phones which can even access GPS , GPRS, Wifi, NFC, and lot of other cool and advanced features which you cannot even imagine. So in this Mobile world of this complication. Android is one of those operating system platforms which made it easy for manufacturers to design top class phones. Android is the first step in the vision of creating a better mobile phone. It is a complete open mobile platform software stack recently release by Google. Android can be run on mobile devices from companies that have come together to form the Open Handset Alliance.




















TABLE OF CONTENT

NUMBER                                    TITLE                                           

1.                          INTRODUCTION                                                                        

2.                      THE BIRTH OF ANDROID                                                                      
               
3.                    ANDROID VERSIONS                                                                                  

4.                     FEATURES                                                                                                                 

5.                    OPERATION                                                                                                           

6.                            ARCHITECTURE                                                                                          

7.                    What Androids Are Made Of                                                                    
                    

8.                    ANDROID UI                                                                                                          
9.                         ANDROID SQLITE DATABASE                                                                      
10.                       APPLICATION LIFECYCLE                                                                                 

11.                     What makes Android special?                                                                                     

12.                      Advantages and  Disadvantages                                                                             

13.                      SAMPLE PROGRAMS                                                                             

14.                      CONCLUSION AND FUTURE SCOPE          







                         1.                               INTRODUCTION

 Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Android is a software platform and operating  system for mobile devices based on the Linux operating system and developed by Google and the Open Handset Alliance. It allows developers to write managed code in a Java-like language that  utilizes Google-developed Java libraries, but does not support programs developed in native  code.
The unveiling of the Android platform on 5 November 2007 was announced with the  founding of the Open Handset Alliance, a consortium of 34 hardware, software and telecom   companies devoted to advancing open standards for mobile devices. When released in 2008,most of the Android platform will be made available under the Apache free-software and  open-source license.



2.                          THE BIRTH OF ANDROID

 Google Acquires Android Inc.
In July 2005, Google acquired Android Inc., a small startup company based in PaloAlto, CA. Android's co-founders who went to work at Google included Andy Rubin(co-founder of Danger), Rich Miner (co-founder of Wildfire Communications, Inc),Nick Sears (once VP at T-Mobile), and Chris White (one of the first engineers at WebTV). At the time, little was known about the functions of Android Inc. other than they made software for mobile phones.
At Google, the team, led by Rubin, developed a Linux-based mobile device OS which they marketed to handset makers and carriers on the premise of providing flexible, upgradeable system. It was reported that Google had already lined up a series of hardware component and software partners and signaled to carriers that it was open to various degrees of cooperation on their part.

 Open Handset Alliance Founded
On 5 November 2007, the Open Handset Alliance, a consortium of several companies which include Google, HTC, Intel, Motorola, Qualcomm, T-Mobile, Sprint Nextel and NVIDIA, was unveiled with the goal to develop open standards for mobile devices. Along with the formation of the Open Handset Alliance, the OHA also unveiled their first product, Android, an open source mobile device platform based on the Linux operating system.
 
Hardware
Google has unveiled at least three prototypes for Android, at the Mobile World Congress on February 12, 2008. One prototype at the ARM booth displayed several basic Google applications. A 'd-pad' control zooming of items in the dock with a relatively quick response.A prototype at the Google IO conference on May 28, 2008 had a 528 MHz Qualcomm processor and a Synaptics capacitive touch screen, and used the UMTS cellular standard. It had 128 MB of RAM and 256 MB of flash, showing that Android's memory requirements are reasonable. The demo was carried out using a 3.6 Mbit/s HSDPA connection.
3.                          ANDROID VERSIONS

Android Beta
  • First Version of Android.
  • The focus of Android beta is testing incorporating the usability.
  •  Android beta will generally have many more problems on speed and performance.

Android Astro 1.0
  • First full version of android.
  • Released on September 23, 2008.
  • Wi-Fi and Bluetooth support.
  • Quite slow in operating.
  • Copy and paste feature in the web  browser is not present.

Android Cupcake 1.5
  • Released on April 30, 2009.
  •  Added auto-rotation option.
  •  Copy and Paste feature added in the web browser.
  •  Increased speed and performance.

Android Donut 1.6
  • Released on September 15, 2009.
  • Voice search and Search box were added.
  • Faster OS boot times and fast web browsing experience.
  • Typing is quite slower.

Android Éclair 2.0/2.1
  • Released on October 26, 2009.
  • Improved typing speed on virtual keyboard, with smarter dictionary.
  • No Adobe flash media support.
Android Froyo 2.2
  • Released on May 20, 2010.
  • Support for Adobe Flash 10.1
  • Improved Application launcher with better browser
  • No internet calling.

Android Gingerbread 2.3
  • Released on December 6, 2010.
  • Updated User Interface with high efficiency and speed
  • Internet calling
  • One touch word selection and copy/paste.
  • New keyboard for faster word input.
  • More successful version of Android than previous versions.
  • Not supports multi-core processors.

Android Honeycomb 3.0
  • Released on February 22, 2011.
  • Support for multi-core processors
  • Ability to encrypt all user data.
  • This version of android is only available for tablets.

Android IceCreamSandwich(ICS) 4.0
  • Released on November 14, 2011.
  • Virtual button in the UI.
  • A new typeface family for the UI, Roboto.
  • Ability to shut down apps that are using data in the background

Android JellyBean 4.1
  • Released on June 27, 2012.
  • Smoother user interface.
  • Google Now- gives information about your current time, live scores, weather conditions, suggests bars and restaurants near you.
  • Search experience is increased with knowledge graph.
  • Provides a better and smarter keyboard.
  • Viewing photos is faster and easier with Android Jelly Bean.
  • Personalizing the home screen become easier and widgets can resize themselves.
  • Expandable and more interactive notifications.

Android KitKat 4.4
  • Better Memory Management - KitKat is designed to run on devices with as little as 512MB of RAM. 
  • Improved Google Now
  • Hangouts App Upgraded
  • Smarter Caller ID
  • Integration With Cloud Storage
  • Built-In Sensors

Android Lollipop 5.1
  • Released on June , 2012.
  • Better Wi-Fi and Bluetooth controls
  • Better device protection
  • Notifications can be flicked away
  • No more crappy Wi-Fi connections

Android Marshmallow 6.0
      Released on October  , 2015.
      Portable storage (Cloud/Fog)
      New power management schemes
      Native support for fingerprint recognition



4.                                   FEATURES


Application Framework
It is used to write applications for Android. Unlike other embedded mobile environments, Android applications are all equal, for instance, an applications which come with the phone are no different than those that any developer writes. The framework is supported by numerous open source libraries such as openssl, SQLite and libc. It is also supported by the Android core libraries. From the point of security, the framework is based on UNIX file system permissions that assure applications have only those abilities that mobile phone owner gave them at install time.

Dalvik Virtual Machine
It is extremely low-memory based virtual machine, which was designed especially for Android to run on embedded systems and work well in low power situations. It is also tuned to the CPU attributes. The Dalvik VM creates a special file format (.DEX) that is created through build time post processing. Conversion between Java classes and .DEX format is done by included “dx” tool

Integrated Browser
Google made a right choice on choosing Web Kit as open source web browser. They added a two pass layout and frame flattening. Two pass layout loads a page without waiting for blocking elements, such as external CSS or external JavaScript and after a while renders again with all resources downloaded to the device. Frame flattening converts founded frames into single one and loads into the browser. These features increase speed and usability browsing the internet via mobile phone.

 Optimized Graphics
As Android has 2D graphics library and 3D graphics based on OpenGL ES 1.0, possibly we will see great applications like Google Earth and spectacular games like Second Life, which come on Linux version. At this moment, the shooting legendary 3D game Doom was presented using Android on the mobile phone.
SQLite
Extremely small (~500kb) relational database management system, which is integrated in Android. It is based on function calls and single file, where all definitions, tables and data are stored. This simple design is more than suitable for a platform such as Android.

Handset Layouts
The platform is adaptable to both larger, VGA, 2D graphics library, 3D graphics library based on OpenGL ES 1.0 specifications, traditional smart phone layouts. An underlying 2D graphics engine is also included. Surface Manager manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications

 Data Storage
SQLite is used for structured data storage .SQLite is a powerful and lightweight relational database engine available to all applications.

 Connectivity
Android supports a wide variety of connectivity technologies including GSM,CDMA , Bluetooth, EDGE, EVDO, 3G and Wi-Fi.

 Messaging
SMS, MMS, and XMPP are available forms of messaging including threaded text messaging.

Web Browser
The web browser available in Android is based on the open-source WebKit application framework. It includes LibWebCore which is a modern web browser engine which powers both the Android browser and an embeddable web view




Java Virtual Machine
Software written in Java can be compiled into Dalvik byte codes and executed in the Dalvik virtual machine, which is a specialized VM implementation designed for mobile device use, although not technically a standard Java Virtual Machine.

Media Support
Android will support advanced audio/video/still media formats such as MPEG-4, H.264, MP3, and AAC, AMR, JPEG, PNG, GIF.

Additional Hardware Support
Android is fully capable of utilizing video/still cameras, touchscreens, GPS,compasses, accelerometers, and accelerated 3D graphics.

Development Environment
Includes a device emulator, tools for debugging, memory and performance profiling,a plugin for the Android studio IDE. There are a number of hardware dependent features, for instance, a huge media and connections support, GPS, improved support for Camera and simply GSM telephony. A great work was done for the developers to start work with Android using device emulator, tools for debugging and plugin for Android studio IDE.




5.                                   OPERATION

 Android Runtime
Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

Linux Kernel
Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.
It helps to manage security, memory management, process management, network stack and other important issues. Therefore, the user should bring Linux in his mobile device as the main operating system and install all the drivers required in order to run it.
Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user. Underlying all applications is a set of services and systems.




6.                          ARCHITECTURE

The following diagram shows the major components of the Android operating system.Each section is described in more detail below.
Fig1: Architecture of Android
Linux Kernel
Android Architecture is based on Linux 2.6 kernel. It helps to manage security, memory management, process management, network stack and other important issues. Therefore, the user should bring Linux in his mobile device as the main operating system and install all the drivers required in order to run it. Android provides the support for the Qualcomm MSM7K chipset family. For instance, the current kernel tree supports Qualcomm MSM 7200A chipsets, but in the second half of 2008 we should see mobile devices with stable version Qualcomm MSM 7200,which includes major features:
v  WCDMA/HSUPA and EGPRS network support
v  Bluetooth 1.2 and Wi-Fi support
v  Digital audio support for mp3 and other formats
v  Support for Linux and other third-party operating systems
v  Java hardware acceleration and support for Java applications
v  Qcamera up to 6.0 megapixels
v  gpsOne – solution for GPS
Libraries
In the next level there are a set of native libraries written in C/C++, which are responsible for stable performance of various components. For example, Surface Manager is responsible for composing different drawing surfaces on the mobile screen. It manages the access for different processes to compose 2D and 3D graphic layers.OpenGL ES and SGL make a core of graphic libraries and are used accordingly for 3D and 2D hardware acceleration. Moreover, it is possible to use 2D and 3D graphics in the same application in Android. The media framework was provided by PacketVideo, one of the members of OHA. It gives libraries for a playback and recording support for all the major media and static image files.FreeType libraries are used to render all the bitmap and vector fonts. For data storage, Android uses SQLite. As mentioned before, it is extra light rational management system, which locates a single file for all operations related to database. WebKit, the same browser used by Apples’ Safari, was modified by Android in order to fit better in a small size screens.

Android Runtime

At the same level there is Android Runtime, where the main component Dalvik Virtual Machine is located. It was designed specifically for Android running in limited environment, where the limited battery, CPU, memory and data storage are the main issues. Android gives an integrated tool “dx”, which converts generated byte code from .jar to .dex file, after this byte code becomes much more efficient to run on the small processors.

 Figure 2: Conversion from .java to .dex file
As the result, it is possible to have multiple instances of Dalvik virtual machine running on the single device at the same time. The Core libraries are written in Java language and contains of the collection classes, the utilities, IO and other tools.
Application Framework
After that, there is Application Framework, written in Java language. It is a toolkit that all applications use, ones which come with mobile device like Contacts or SMS box, or applications written by Google and any Android developer. It has several components.
The Activity Manager manages the life circle of the applications and provides a common navigation back stack for applications, which are running in different processes. The Package Manager keeps track of the applications, which are installed in the device. The Windows Manager is Java programming language abstraction on the top of lower level services that are provided by the Surface Manager. The Telephony Manager contains of a set of API necessary for calling applications. Content Providers was built for Android to share a data with other applications, for instance, the contacts of people in the address book can be used in other applications too. The Resource Manager is used to store localized strings, bitmaps, layout file descriptions and other external parts of the application. The View System generates a set of buttons and lists used in UI. Other components like Notification manager is used to customize display alerts and other functions.

 Application Layer
At the top of Android Architecture we have all the applications, which are used by the final user. By installing different applications, the user can turn his mobile phone into the unique, optimized and smart mobile phone. All applications are written using the Java programming language.






7.                     What Androids Are Made Of

Android Applications

An application consists of one or more components that are defined in the application's manifest file. A component can be one of the following:

1.An Activity
2.A Service
3.A intent receiver
4.A content provider


Activities

The building block of the user interface is the activity. You can think of an activity as being the Android analogue for the window or dialog in a desktop application, or the page in a classic Web app. Android is designed to support lots of cheap activities, so you can allow users to keep clicking to bring up new activities and tapping the BACK button to back up, just like they do in a Web browser.


Services

Activities are short-lived and can be shut down at any time. Services, on the other hand, are designed to keep running, if needed, independent of any activity. You might use a service for checking for updates to an RSS feed, or to play back music even if the controlling activity is no longer operating. You will also use services for scheduled tasks ("cron jobs") and for exposing custom APIs to other applications on the device, though those are relatively advanced capabilities.

Content Providers

Content providers provide a level of abstraction for any data stored on the device that is accessible by multiple applications. The Android development model encourages you to make your own data available to other applications, as well as your own building a content provider lets you do that, while maintaining complete control over how your data gets accessed.






    Intent Receiver
Wakes up a predefined action through the external event. For example,for the application like Email Inbox, the developer should have intent receiver and register his code through XML to wake up an alarm notification, when the user receives email.


Intents

Intents are system messages, running around the inside of the device, notifying applications of various events, from hardware state changes (e.g., an SD card was inserted), to incoming data (e.g., an SMS message arrived), to application events (e.g., your activity was launched from the device's main menu). Not only can you respond to an Intent, but you can create your own, to launch other activities, or to let you know when specific situations arise (e.g., raise such-and-so Intent when the user gets within 100 meters of this-and-such location).

      An Intentis a declaration of need.It is made up of various pieces including: desired actionor service, data, and categoryof component that should handle the intent and instructions on how to launch a target activity. IntentFilter is a trigger, a declaration of capability and interest in offering assistance to those in need. IntentFilter may be generic or specific with respect to which Intents it offers to service. Intent is an abstract description of an operation to be performed.Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. The primary pieces of information in an intent are:

Some examples of Intent’s action/data pairs are:

ACTION_VIEWcontent://contacts/1--Display information about the person whose identifier is "1".
ACTION_DIALcontent://contacts/1--Display the phone dialer with the person filled in.
ACTION_VIEWtel:123--Display the phone dialer with the given number filled in
ACTION_DIAL tel:123--Display the phone dialer with the given number filled in.
ACTION_EDITcontent://contacts/1--Edit information about the person whose identifier is "1".
ACTION_VIEWcontent://contacts/--Display a list of people, which the user can browse through.


Dissecting Intents

1.Component name The name of the component that should handle the intent ( for example "com.example.project.app.MyActivity1" ).
2.Action A string naming the action to be performed —or, in the case of broadcast intents, the action that took place and is being reported (for example: ACTION_VIEW, ACTION_CALL, ACTION_TIMEZONE_CHANGED, … ).
3.Data The URI of the data to be acted on and the MIME type of that data (for example tel:/216 555-1234 , "http://maps.google.com”, ... ).
4.Category A string containing additional information about the kind of component that should handle the intent (for example CATEGORY_BROWSABLE, CATEGORY_LAUNCHER, … ).
5.Extras Key-value pairs for additional information that should be delivered to the component handling the intent.
6.Flags of various sorts.









Intent Resolution

Intents can be divided into two groups:

Explicit intents designate the target component by its name, typically used for an activity starting a subordinate service or launching a sister activity.
Implicit intents do not name a target (the field for the component name is blank). Implicit intents are often used to activate components in other applications. Late binding applies.

Whenever possible Android delivers an explicit intent to an instance of the designated target class.

IntentFilters

The IntentFilter defines the relationship between the Intent and the application. IntentFilters can be specific to the data portion of the Intent, the action portion, or both. IntentFilters also contain a field known as a category. A category helps classify the action.

For example, the category named

CATEGORY_LAUNCHER instructs Android that the Activity containing this IntentFilter should be visible in the home screen. When an Intent is dispatched, the system evaluates the available Activities, Services, and registered Broadcast Receivers and routes the Intent to the most appropriate recipient (see next Figure).
 


To inform the system which implicit intents they can handle, activities, services, and broadcast receivers can have one or more intent filters. Each filter describes a capability that the component is willing to receive. An explicit intent is always delivered to its target, no matter what it contains; the filter is not consulted. But an implicit intent is delivered to a component only if it can pass through one of the component's filters
AndroidManifest.xml

The AndroidManifest.xml file is the control file that tells the system what to do with all the top-level components (specifically activities, services, intent receivers, and content providers described below). For instance, this is the "glue" hat actually specifies which Intents your Activities receive. A developer should predefine and list all components, which he wants to use in the specific AndroidManifest.xml file. It is a required file for all the applications and is located in the root folder. It is possible to specify all global values for the package, all the components and its classes used, intent filters, which describe where and when the certain activity should start, permissions and instrumentation like security control and testing.


Here is an example of AndroidManifest.xml file:
1. <?xml version="1.0" encoding="utf-8"?>
2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3. package="dk.mdev.android.hello">
4. <application android:icon="@drawable/icon">
5. <activity class=".HelloAndroid" android:label="@string/app_name">
6. <intent-filter>
7. <action android:value="android.intent.action.MAIN" />
8. <category android:value="android.intent.category.LAUNCHER"/>
9. </intent-filter>
10. </activity>
11. </application>
12. </manifest>
The line 2 is a namespace declaration, which makes a standard Android attributes available for that application. In the line 4 there is a single <application> element, where the developer specifies all application level components and its properties used by the package. Activity class in the line 5 represents the initial screen the user sees and it may have one or more <intent-filter> elements to describe the actions that activity supports.

Padding

Widgets have a minimum size, one that may be influenced by what is inside of them. So, for example, a Button will expand to accommodate the size of its caption. You can control this size using padding. Adding padding will increase the space between the contents (e.g., the caption of a Button) and the edges of the widget.

Padding can be set once in XML for all four sides (android:padding) or on a
per-side basis (android:paddingLeft, etc.). Padding can also be set in Java via the setPadding() method. The value of any of these is a dimension – a combination of a unit of measure and a count. So, 5px is 5 pixels, 10dip is 10 density-independent
pixels, or 2mm is 2 millimeters







8.                                   ANDROID UI
The Android UI framework provides some basic UI components, that are called controls or widgets, helping developers while coding and building an app.


Views
The View class is the basic class that all the components extend. A View draws something on a piece of screen and it is responsible to handle events while user interacts with it. Even the generic ViewGroup class extends View. A ViewGroup
is a special View that holds other views and places these views following some rules. We will see that Android provides some specialized views that helps us to handle text, images, user inputs, buttons and so on.

All these views have some key aspects in common:

All views have a set of properties: These properties affect the way the view is rendered. There is a set of properties common to all views, while there are some other properties depending on the type of view.

Focus: The system manages the focus on each view and depending on the user input, we can modify and force the focus on a specific view.

Listeners: All views have listeners which are used to handle events when the user interacts with the view. We can register our app to listen to specific events that occur on a view.

Visibility: We can control if a view is visible or not and we can change the view visibility at runtime too.A view property is a key value pair that we can use to customize the view behavior. The property values can be:
• a number
• a string
• a reference to a value written somewhere else

The first two options are trivial, the third is the most interesting one because we can create a file (always in XML) that holds a list of values and we can reference it in our property value. This is the best approach to follow especially when we use themes
and styles or we want to support multi-language apps.

One of the most important property is view id: this is a unique identifier for the view and we can look up a specific view using
this id. This is a “static” property meaning we cannot change it once we have defined it.




When we want to set a view property,

<TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="@string/hello_world" />

Two properties that play an important role are layout_width and layout_height. These two properties define how large and how tall should be the view. We can use two predefined values:
• MATCH_PARENT
• WRAP_CONTENT

With MATCH_PARENT value, we mean that we want our view as big as its parent that holds it, while with WRAP_CONTENT we specify that our view must be big enough to hold its content. Android provides several standard components and of course if we cannot find a component that fulfills our needs, we can always implement a custom view. Using a custom view, we can define what our view will draw on the screen and its behaviour. We can even define custom properties that affect the view’s behavior. In this case, we have to extend the basic View class and override some methods.
           
TextView component

This is one of the simplest components.

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

ImageView component

This component is used to show an image on the screen. The image we want to show can be placed inside our apk or we can load it remotely. In the first case, our image has to be placed under the res/drawable directory. Base on what we discussed in our previous chapter, we already know we have to keep in mind that our app can run on multipe devices with different screen density. To better support different screen densities, we can create different images with different resolutions. The res/drawable
directory is the default directory where the system looks if it cannot find an image with the right density for the screen. Generally speaking, we have to create at least four different image with different resolutions, in fact we can notice in our IDE that there are at least five directories:
• drawable-ldpi (not supported any more)
• drawable-mdpi (medium dpi)
• drawable-hdpi (high dpi)
• drawable-xhdpi (extra-high dpi)
• drawable-xxhdpi (x-extra-high dpi)
• drawable



Input controls

Input controls are components that the user can interact with. Using a component like that, you can, for example, give to the user the chance to insert some values. The Android UI framework provides a wide range of input controls: text field, input field, toggle buttons, radio buttons, buttons, checkbox, pickers and so on. Each of them has a specialized class and we can build complex interfaces using these components. There is a list of common components, below, with the class that handles it:




Button component that this is widely used in Android UI.
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
android:id="@+id/Btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click here!" />

</RelativeLayout>
Button id we used @+id meaning we are adding a new id and the android:text attribute is the string we want to show on the button.





9.                ANDROID SQLITE DATABASE

SQLite is a open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database , you don't need to establish any kind of connections for it like JDBC,ODBC e.t.c . The main package is android.database.sqlite that contains the classes to manage your own databases .

Database - Creation
In order to create a database you just need to call this method openOrCreateDatabase with your database name and mode as a parameter. It returns an instance of SQLite database which you have to recieve in your own object.Its syntax is given below .
Eg:
SQLiteDatabse mydatabase = openOrCreateDatabase("your database name",MODE_PRIVATE,null);

Apart from this , there are other functions availaible in the databsae package , that does this job. They are listed below

Sr.No
Method & Description
1
openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags, DatabaseErrorHandler errorHandler) This method only opens the existing database with the appropriate flag mode. The common flags mode could be OPEN_READWRITE OPEN_READONLY
2
openDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags) It is similar to the above method as it also opens the exisiting database but it does not define any handler to handle the errors of databases
3
openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory) It not only opens but create the datbase if it not exists. This method is equivalent to openDatabase method
4
openOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory) This method is similar to above method but it takes the File object as a path rather then a string. It is equavilent to file.getPath()




Database - Insertion
Eg:
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS STUDENT(Username VARCHAR,Password VARCHAR);"); mydatabase.execSQL("INSERT INTO STUDENT VALUES('admin','admin');");
This will insert some values into our table in our database. Another method that also does the same job but take some additional parameter is given below
Sr.No
Method & Description
1
execSQL(String sql, Object[] bindArgs) This method not only insert data , but also used to update or modify already existing data in database using bind arguments

Database - Fetching
We can retrieve anything from datbase using an object of the Cursor class. We will call a method of this class called rawQuery and it will return a resultset with the cursor pointing to the table. We can move the cursor forward and retrieve the data.
Eg:
Cursor resultSet = mydatbase.rawQuery("Select * from TutorialsPoint",null); resultSet.moveToFirst(); String username = resultSet.getString(1); String password = resultSet.getString(2);
There are other functions availaible in the Cursor class that allows us to effectively retrieve the data. That includes
Sr.No
Method & Description
1
getColumnCount() This method return the total number of columns of the table.
2
getColumnIndex(String columnName) This method returns the index number of a column by specifying the name of the column
3
getColumnName(int columnIndex) This method returns the name of the column by specifying the index of the column
4
getColumnNames() This method returns the array of all the column names of the table.
5
getCount() This method returns the total number of rows in the cursor
6
getPosition() This method returns the current position of the cursor in the table
7
isClosed() This method returns true if the cursor is closed and return false otherwise .



10.                       Application Lifecycle

In Android, every application runs in its own process, which gives better performance in security, protected memory and other benefits. Therefore, Android is responsible to run and shut down correctly these processes when it is needed. It is important that application developers understand how different application components (in particular Activity, Service, and intent Receiver) impact the lifetime of the application's process. Not using these components correctly can result in the system killing the application's process while it is doing important work.
To determine which processes should be killed when low on memory, Android places each process into an "importance hierarchy" based on the components running in them and the state of those components. These process types are (in order of importance).

1. A foreground process is one that is required for what the user is currently doing.Various application components can cause its containing process to be considered foreground in different ways. A process is considered to be in the foreground if any of the following conditions hold:
i. It is running an Activity at the top of the screen that the user is interacting with (its onResume() method has been called).
ii. It has a Broadcast Receiver that is currently running (its intent Receiver .onReceive() method is executing).
iii. It has a Service that is currently executing code in one of its callbacks (Service.onCreate(), Service.onStart(), or Service.onDestroy()).
There will only ever be a few such processes in the system, and these will only be killed as a last resort if memory is so low that not even these processes can continue to run. Generally, at this point, the device has reached a memory paging state, so this action is required in order to keep the user interface responsive.

2.A visible process is one holding an Activity that is visible to the user on-screen but not in the foreground (its onPause() method has been called). This may occur, for example, if the foreground Activity is displayed as a dialog that allows the previous Activity to be seen behind it. Such a process is considered extremely important and will not be killed unless doing so is required to keep all foreground processes running.

3.A service process is one holding a Service that has been started with the start Service() method. Though these processes are not directly visible to the user, they are generally doing things that the user cares about (such as background mp3 playback or background network data upload or download), so the system will always keep such processes running unless there is not enough memory to retain all foreground and visible process.

4. A background process is one holding an Activity that is not currently visible to the user (its on Stop() method has been called). These processes have no direct impact on the user experience. Provided they implement their Activity life-cycle correctly (see Activity for more details), the system can kill such processes at any time to reclaim memory for one of the three previous processes types. Usually there are many of these processes running, so they are kept in an LRU list to ensure the process that was most recently seen by the user is the last to be killed when running low on memory.

5. An empty process is one that doesn't hold any active application components.The only reason to keep such a process around is as a cache to improve startup time the next time a component of its application needs to run. As such, the system will often kill these processes in order to balance overall system resources between these empty cached processes and the underlying kernel caches.


11.                        What makes Android special?

There are already many mobile platforms on the market today, including Symbian, iPhone, Windows Mobile, BlackBerry, Java Mobile Edi-tion, Linux Mobile (LiMo), and more.While some of its features have appeared before, Android is the first environment that combines:

A truly open, free development platform based on Linux and open source. Handset makers like it because they can use and customize the platform without paying a royalty. Developers like it because they know that the platform “has legs” and is not locked into any one vendor that may go under or be acquired.

A component-based architecture inspired by Internet mash-ups. Partsof one application can be used in another in ways not originallyenvisioned by the developer. You can even replace built-in components with your own improved versions. This will unleash a new round of creativity in the mobile space.

Tons of built-in services out of the box. Location based services use GPS or cell tower triangulation to let you customize the user experience depending on where they are. A full-powered SQL database lets you harness the power of local storage for occasionally connected computing and synchronization. Browser and Map views can be embedded directly in your applications. All these built-in capabilities help to raise the bar on functionality while loweringyour development costs.

Automatic management of the application life cycle. Programs areisolated from each other by multiple layers of security, which will provide a level of system stability not seen before in smart phones.The end user will no longer have to worry about what applications are active, or close some programs so that others can run.Android is optimized for low-power, low-memory devices in a fundamental way that no previous platform has attempted.


High quality graphics and sound. Smooth, anti-aliased 2D vector graphics and animation inspired by Flash is melded with 3D accelerated OpenGL graphics to enable new kinds of games and business applications. Codecs for the most common industry standard audio and video formats are built right in, including H.264 (AVC), MP3, and AAC.

Portability across a wide range of current and future hardware.All Your programs are written in Java and executed by Android’s Dalvik virtual machine so your code will be portable across ARM,x86, and other architectures. Support for a variety of input methods is included such as keyboard, touch, tilt, camera, voice, and trackball. User interfaces can be customized for any screen resolution and orientation.Android is a fresh take on the way mobile applications interact with users, along with the technical underpinnings to make it possible. But the best part of Android is the software that you are going to write for it


12.                        Advantages and  Disadvantages


Advantages
Open - Android allows you to access core mobile device functionality through standard API calls.

All applications are equal Android does not differentiate between the phone's basic and third-party applications even the dialer or home screen can be replaced.

Breaking down boundaries - Combine information from the web with data on the phone such as contacts or geographic location to create new user experiences.

Fast and easy development - The SDK contains what you need to build and run Android applications, including a true device emulator and advanced debugging tools.

Disadvantages

Security - Making source code available to everyone inevitably invites the attention of black hat hackers.

Open Source A disadvantage of open-source development is that anyone can scrutinize the source code to find vulnerabilities and write exploits.

Login Platform doesn't run on an encrypted file system and has a vulnerable log-in.

Incompetence - Google’s dependence on hardware and carrier partners puts the final product out of their control.




13.                           SAMPLE PROGRAMS

1. Program used almost all the UI components

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/Btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click here!" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Btn"
android:layout_below="@+id/Btn"
android:layout_marginTop="29dp"
android:text="CheckBox" />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox1"
android:layout_below="@+id/checkBox1"
android:layout_marginTop="20dp"
android:text="ToggleButton" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/toggleButton1"
android:layout_centerVertical="true"
android:ems="10"
android:hint="Your name here" >

    <requestFocus />
</EditText>

<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/toggleButton1"
android:layout_alignBottom="@+id/toggleButton1"
android:layout_alignParentRight="true"
android:text="Switch" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="24dp" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="40dp"
android:text="Option 1" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioButton1"
android:layout_below="@+id/radioButton1"
android:text="Option 2" />
 </RadioGroup>

</RelativeLayout>

HELLO WORLD
·        MainActivity.java
  package com.example.madgeek.helloworld;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  public class MainActivity extends AppCompatActivity
   {
            @Override
            protected void onCreate(Bundle savedInstanceState)
       {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                     }
        }

·        activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    <TextView android:text="Hello World!"
        android:textSize="50dp"
        android:textColor="@color/colorAccent"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

 
LOGIN FORM
·         MAIN ACTIVITY.JAVA
package com.filmadictersnetwork.fans.sample;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    SQLiteDatabase db;
    EditText edituser;
    EditText editpass;
    String user,pwd;
    Cursor c;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);}
    public void onlog(View view){
        db=openOrCreateDatabase("mydb",MODE_PRIVATE,null);
        db.execSQL("CREATE TABLE IF NOT EXISTS login(user VARCHAR,pwd VARCHAR,email VARCHAR)");
        edituser=(EditText)findViewById(R.id.editus);
        editpass=(EditText)findViewById(R.id.editpas);
        if (user.equals(" ")||pwd.equals(" ")){
            Toast.makeText(this,"Fill the Fields",Toast.LENGTH_SHORT).show();}
        else{
            c=db.rawQuery("select * from login where user'"+user+"'and pwd='"+pwd+"'",null);}
        if (c.moveToFirst()){   Intent i=new Intent(this,welcome.class);
            startActivity(i);
            db.close();
            finish();
        }
       else{
            Toast.makeText(this,"wrong fields",Toast.LENGTH_SHORT).show();}
    }
    public void onsignup(View view){
        Intent j=new Intent(this,signup.class);
        startActivity(j);
    }
}
·         ACTIVITY MAIN.XML
<?xml version="1.0" encoding="utf-8"?>
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
    android:id="@+id/user"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content”>
    <TextView
        android:text="USERNAME"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"/>
    <EditText
        android:id="@+id/editus"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"/></LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/user"
        android:id="@+id/linearLayout">
    <TextView
        android:text="PASSWORD"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"/>
        <EditText
            android:id="@+id/editpas"
            android:inputType="textPassword"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/></LinearLayout>
    <Button
        android:onClick="onlog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LOGIN"
        android:layout_below="@+id/linearLayout"  />
    <Button
        android:onClick="onsignup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIGN UP"
        android:layout_below="@+id/linearLayout"/>
</RelativeLayout>







·        SIGNUP ACTIVITY.JAVA
package com.filmadictersnetwork.fans.sample;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class signup extends AppCompatActivity {
   SQLiteDatabase db;
    EditText edituser;
    EditText editpass;
    EditText editemail;
    String user,pwd,email;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);}
    public void onsigup(View view){
        db=openOrCreateDatabase("mydb",MODE_PRIVATE,null);
        db.execSQL("CREATE TABLE IF NOT EXISTS login(user VARCHAR,pwd VARCHAR,email VARCHAR)");
        edituser=(EditText)findViewById(R.id.usr);
        editpass=(EditText)findViewById(R.id.paswd);
        editemail=(EditText)findViewById(R.id.mail);
        if (user.equals(" ")||pwd.equals(" ")||email.equals(" ")){
            Toast.makeText(this,"Fill the Fields",Toast.LENGTH_SHORT).show
        else
        { db.execSQL("insert into login values('"+user+"','"+pwd+"','"+email+"'");
            Intent k=new Intent(this,welcome.class);
            startActivity(k); } } }
·        ACTIVITY SIGNUP.XML
<?xml version="1.0" encoding="utf-8"?>
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.filmadictersnetwork.fans.sample.signup">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout1">
        <TextView
            android:id="@+id/usern"
            android:text="USERNAME"
            android:layout_width="0dp"   android:layout_weight="2"
            android:layout_height="wrap_content"/>
        <EditText
            android:layout_width="0dp" android:layout_weight="2"
            android:layout_height="wrap_content"
            android:id="@+id/usr" /></LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout2"
        android:layout_below="@+id/linearLayout1">
    <TextView
       android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="PASSWORD"  />
    <EditText
        android:inputType="textPassword"
        android:layout_width="0dp"          android:layout_weight="2"
        android:layout_height="wrap_content"
        android:id="@+id/paswd"  /> </LinearLayout>
    <LinearLayout
        android:id="@+id/linear3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linearLayout2" >
    <TextView
        android:text="Email"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"  />
    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:id="@+id/mail" />  </LinearLayout>
    <Button
        android:onClick="onsigup"
        android:layout_below="@+id/linear3"
        android:text="SIGN UP"
        android:layout_width="fill_parent"
android:layout_height="wrap_content" /></RelativeLayout>
·         WELCOME ACTIVITY.JAVA
package com.filmadictersnetwork.fans.sample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class welcome extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
    }
}
·        ACTIVITY WELCOME.XML
<?xml version="1.0" encoding="utf-8"?>
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.filmadictersnetwork.fans.sample.welcome">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="WELCOME"
        android:textSize="55dp"
        android:textStyle="bold"
        android:textColor="@color/colorPrimaryDark"
        android:layout_centerInParent="true"/>
</RelativeLayout>



13.              CONCLUSION AND FUTURE SCOPE

Android has been criticized for not being all open-source software despite what was
announced by Google. Parts of the SDK are proprietary and closed source, and some
believe this is so that Google can control the platform. Software installed by end-users
must be written in Java, and will not have access to lower level device APIs. This provides end-users with less control over their phone's functionality than other free and open source phone platforms, such as OpenMoko.With all upcoming applications and mobile services Google Android is stepping into the next level of Mobile Internet. Android participates in many of the successful open source projects. That is, architect the solution for participation and the developers will not only come but will play well together. This is notable contrast with Apple and other companies, where such architecture of participation is clearly belated.
The first Android based official devices may well be launched sometime in the early half of 2009. Obviously, that's an age away when it comes to handset design, and Android may well find itself competing against the forthcoming Nokia touch screen phones and maybe even the iPhone 2.           

                               







No comments:

Post a Comment