Monday, January 17, 2011

Android Manifest File , Intents , and Intent Filters


The manifest file

Before Android can start an application component, it must learn that the component exists. Therefore, applications declare their components in a manifest file that's bundled into the Android package, the .apk file that also holds the application's code, files, and resources.
The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things in addition to declaring the application's components, such as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.
But the principal task of the manifest is to inform Android about the application's components. For example, an activity might be declared as follows:
 

The name attribute of the <activity> element names the Activity subclass that implements the activity. The icon and label attributes point to resource files containing an icon and label that can be displayed to users to represent the activity.

Intent filters

An Intent object can explicitly name a target component. If it does, Android finds that component (based on the declarations in the manifest file) and activates it. But if a target is not explicitly named, Android must locate the best component to respond to the intent. It does so by comparing the Intent object to the intent filters of potential targets. A component's intent filters inform Android of the kinds of intents the component is able to handle. Like other essential information about the component, they're declared in the manifest file. 

Intent filter tag contains many information like action , category etc. In android apps the first activity have the inten filter with action value MAIN and category value LAUNCHER  as shown below:
  <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>


Intents

Intent is an asynchronous message which activates the three type of components - activities , services , and  broadcast receivers.For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text.For broadcast receivers, the Intent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.

There are separate methods for activating each type of component:

* An activity is launched (or given something new to do) by passing an Intent object to Context.startActivity() or Activity.startActivityForResult(). 

        *  A service is started (or new instructions are given to an ongoing service) by passing an Intent     object to Context.startService().

  *   An application can initiate a broadcast by passing an Intent object to methods like  Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.Android delivers the intent to all interested broadcast receivers by calling their onReceive() methods.

Now  an example of calling an activity from another activity:- 

Let's make two activities splashActivity and menuActivity . 

In above code calling menuActivity from splashActivity using intent object by directly specifying activity name.
when we don't know the name of the components  we can use action , catagory, or data type options to call the component. 


for more info on intents, intent filter and manifest file you can go to this site 
http://developer.android.com/guide/topics/fundamentals.html


Bindu Kushwaha



Tuesday, January 11, 2011

What is Android?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

The compiled Java code — along with any data and resource files required by the application — is bundled by the aapt tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application.

A central feature of Android is that one application can make use of elements of other applications (provided those applications permit it). For example, if your application needs to display a scrolling list of images and another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. Your application doesn't incorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other application when the need arises.

For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Java objects for that part. Therefore, unlike applications on most other systems, Android applications don't have a single entry point for everything in the application (no main() function, for example). Rather, they have essential components that the system can instantiate and run as needed.

 There are four types of components:

1.Activities :-
 

An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI . While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup).





The visual content of the window is provided by a hierarchy of views — objects derived from the base View class. Each view controls a particular rectangular space within the window. Parent views contain and organize the layout of their children. Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond to user actions directed at that space. Thus, views are where the activity's interaction with the user takes place. For example, a view might display a small image and initiate an action when the user taps that image. Android has a number of ready-made views that you can use — including buttons, text fields, scroll bars, menu items, check boxes, and more.

2.Services:- 

A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class.

It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service through an interface that the service exposes. For the music service, this interface might allow users to pause, rewind, stop, and restart the playback.

Like activities and the other components, services run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback).

Service itself is actually very simple, providing two main features:

    * A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
    * A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.

3.Broadcast receivers:-
 
    A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. Applications can also initiate broadcasts — for example, to let other applications know that some data has been downloaded to the device and is available for them to use.

    An application can have any number of broadcast receivers to respond to any announcements it considers important. All receivers extend the BroadcastReceiver base class.

    Broadcast receivers do not display a user interface. However, they may start an activity in response to the information they receive, or they may use the NotificationManager to alert the user. Notifications can get the user's attention in various ways — flashing the backlight, vibrating the device, playing a sound, and so on. They typically place a persistent icon in the status bar, which users can open to get the message.

4.Content providers:-

    A content provider makes a specific set of the application's data available to other applications. The data can be stored in the file system, in an SQLite database, or in any other manner that makes sense. The content provider extends the ContentProvider base class to implement a standard set of methods that enable other applications to retrieve and store data of the type it controls. However, applications do not call these methods directly. Rather they use a ContentResolver object and call its methods instead. A ContentResolver can talk to any content provider; it cooperates with the provider to manage any interprocess communication that's involved.

Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase.

Monday, January 10, 2011

Android SDK Installation Guide

This guide walks you through the steps needed to install and configure all the appropriate tools you need to get started developing Android applications:

Step1. Supported Operating Systems

           Android applications can be written on the following operating systems:
  •    Windows XP or later
  •    Mac OS X 10.5.8 or later (x86 only)
  •    Linux
Step2.  Space Requirement

       You need around 2GB of space to safely install all the tools you need to
       develop Android applications. This includes installing the JDK, the
       Eclipse IDE, the Android SDK, and the tools and plug-ins.

Step3. Installing the Java Development Kit

       Android applications can be developed using Sun’s JDK 5 or JDK 6. 
       You can read the license agreement and download the latest version 
       of the Java Standard Edition JDK at Sun’s 
       website, http://java.sun.com/javase/downloads/. For specific installation for
       your operating system, see the documentation available with the installation 
       package  you choose.

Step4. Installing the Eclipse IDE

       Most developers use the popular Eclipse IDE for Android development; 
       this IDE is available for Windows, Mac, and Linux operating systems.
      You can develop Android applications using either Eclipse 3.4 (Ganymede) 
       or Eclipse 3.5 (Galileo).You can read the license agreement and download 
      the Eclipse IDE for Java EE  Developers at www.eclipse.org/downloads/.

      The Eclipse package comes as a compressed zip file. There is no installer.
      You unzip the package into the desired folder and then follow the specific
      instructions in the following sections for your target operating system.

Step5.  Installing the Android SDK

      You need to install the Android SDK to develop Android applications.
      The Android SDK includes the Android JAR file (Android application 
      framework classes) as well as Android documentation, tools, and
      sample code.

      The Android SDK is available from the Android Developer website, at
      http://developer.android.com/sdk/index.html. You need to agree to the
     Android license agreement prior to installing the developer package.

Step6.  Installing and Configuring the AndroidPlug-in for Eclipse (ADT)

      The Android Plug-in for Eclipse allows seamless integration with many 
      of the Android development tools. If you’re using Eclipse, it’s highly 
      recommended that you install the in, as it will make your life much easier.
     The Plug-in includes various wizards for creating and debugging Android
     projects.

     To install the Android Plug-in for Eclipse (ADT), you must launch Eclipse
     and install a custom software update. The steps required depend on 
     the version of Eclipse you use. For complete instructions, see the Android 
     developer website,http://developer.android.com/sdk/eclipse-adt.html.

    To install Android Plug-in on Eclipse 3.5 (Galileo), follow these steps:
        1. Launch Eclipse.
        2. Select Help, Install New Software.
        3. Select the Available Software tab.
        4. Click the Add button.
        5. Add the remote site https://dl-ssl.google.com/android/eclipse/. If this
             site fails,try http://dl-ssl.google.com/android/eclipse/.
       6. On the Available Software tab, check the box next to Developer Tools box.
           (Also check the boxes for Android DDMS and Android Development Tools.)
       7. Click the Next button and follow the wizard for installing the tools. Accept
           the terms of the license agreement and click the Finish button.
       8. After the software update completes, restart Eclipse.

       After you install the Android SDK Eclipse plug-in, update your Eclipse 
       preferences to point at the Android SDK you previously downloaded. 
       To do this, launch Eclipse and choose Window, Preferences 
       (or Eclipse, Preferences in Mac OS X). Select the Android preferences 
       and set the path to where you installed the Android SDK.
       Once you have set the path appropriately, you will see a number of
        target SDK versions (Android 1.0, 1.5, 1.6, 2.0, 2.01, 2.1, and so on) 
        listed below SDK Location in the Android Preferences dialog in Eclipse.

Now your computer is ready to develop Android Apps.

Have a nice time.

Bindu Kushwaha
http://geeksonwork.blogspot.com