RSS

Toast Message


A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.

The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.

Summary

Constants
int LENGTH_LONG Show the view or text notification for a long period of time.
int LENGTH_SHORT Show the view or text notification for a short period of time.

toast.java

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class toast extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 Toast.makeText(this, "Hello crave Developer", Toast.LENGTH_SHORT).show();

 }
}
Out Put:

Display image inside Toast Message

toast.xml

toast.java

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends Activity {
 Button btn;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 btn=(Button)findViewById(R.id.btnSimpleToastWithImage);
 btn.setOnClickListener(new OnClickListener() {

 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 Toast toast = null;
 toast = Toast.makeText(getApplicationContext(),
 "Hello, !!!!!!! crave developer !!!!!!", Toast.LENGTH_LONG);
 toast.setGravity(Gravity.CENTER, 0, 0);
 LinearLayout toastView = (LinearLayout) toast.getView();
 ImageView tostimage = new ImageView(getApplicationContext());
 tostimage.dispatchKeyEventPreIme(new KeyEvent(DEFAULT_KEYS_SHORTCUT, 3));
 tostimage.setImageResource(R.drawable.imgandroiddevelop);
 toastView.addView(tostimage, 0);

 toast.show();

 }
 });

 }
}
 
Leave a comment

Posted by on January 10, 2012 in Practical

 

Click on button and display hello world


XML File content

 

<TextView android:layout_height=“wrap_content”

android:id=“@+id/tvText” android:layout_gravity=“center_horizontal”

android:layout_width=“wrap_content” android:visibility=“invisible”></TextView>

<Button android:layout_width=“match_parent”

android:layout_height=“wrap_content” android:text=“@string/displayString”

android:id=“@+id/btnShow” android:layout_weight=“0.0”

android:layout_marginLeft=“40dip” android:layout_marginRight=“40dip”

android:layout_marginTop=“100dip” android:layout_gravity=“center”></Button>

 

Java File

 

package com.skp.show;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

 

public class showText extends Activity {

/** Called when the activity is first created. */

 

private Button btnShow;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

 

btnShow = (Button) findViewById(R.id.btnShow);

btnShow.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

           TextView tvShow = (TextView) findViewById(R.id.tvText);

           tvShow.setVisibility(View.VISIBLE);

           tvShow.setText(“Hey… You Have Clicked Button”);

}

});

}

}

 
Leave a comment

Posted by on January 6, 2012 in Practical

 

How To Add Button Into Your Application?


Input Events

On Android, there’s more than one way to intercept the events from a user’s interaction with your application. When considering events within your user interface, the approach is to capture the events from the specific View object that the user interacts with. The View class provides the means to do so.

Within the various View classes that you’ll use to compose your layout, you may notice several public callback methods that look useful for UI events. These methods are called by the Android framework when the respective action occurs on that object. For instance, when a View (such as a Button) is touched, the onTouchEvent() method is called on that object. However, in order to intercept this, you must extend the class and override the method. However, extending every View object in order to handle such an event would not be practical. This is why the View class also contains a collection of nested interfaces with callbacks that you can much more easily define. These interface, called event listeners, are your ticket to capturing the user interaction with your UI.

Event Listeners

An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.

Included in the event listener interfaces are the following callback methods:

onClick()

From View.OnClickListener. This is called when the user either touches the item (when in touch mode), or focuses upon the item with the navigation-keys or trackball and presses the suitable “enter” key or presses down on the trackball.

onLongClick()

From View.OnLongClickListener. This is called when the user either touches and holds the item (when in touch mode), or focuses upon the item with the navigation-keys or trackball and presses and holds the suitable “enter” key or presses and holds down on the trackball (for one second).

onFocusChange()

From View.OnFocusChangeListener. This is called when the user navigates onto or away from the item, using the navigation-keys or trackball.

onKey()

From View.OnKeyListener. This is called when the user is focused on the item and presses or releases a key on the device.

onTouch()

From View.OnTouchListener. This is called when the user performs an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item).

onCreateContextMenu()

From View.OnCreateContextMenuListener. This is called when a Context Menu is being built (as the result of a sustained “long click”). See the discussion on context menus in the Menus developer guide.

These methods are the sole inhabitants of their respective interface. To define one of these methods and handle your events, implement the nested interface in your Activity or define it as an anonymous class. Then, pass an instance of your implementation to the respective View.set…Listener() method. (E.g., callsetOnClickListener() and pass it your implementation of the OnClickListener.)

How to add button?

As you have seen the list of events that can be attached with a button, now we will move on for adding a button to your workspace area.

Steps:

To add a button, you have to open .XML file where you have to select graphical mode. Now you can see a “Palette” on the left side as shown in the below figure, there you will find an object called “Button”, just drag and drop it on the screen area (which is in black color in the snapshot shown to you).

 

To change the appearance of the button you can switch to the text view i.e ‘main.xml’ which is next to the ‘Graphical Layout’ option. If you have a query how to change the text seen on the button, then you can do it by replacing “Button” with “Click Me” to look more attractive.

 

 

Now after making changes in the “main.xml” file, do not forget to save it else it will display an error. After doing it you can open the ‘MainActivity.java’ (there can be other name of the file in your case) to add the code of button listener which will carry out the task of displaying the text into the label.

 

 

Here, first we have created object of the button (as Button bt) and to call the event when it is being clicked, we have used “onClick()” method. Just ensure that the whole code that you have in your file matches with the snap as shown in the above step. As you know, Java language is case sensitive, ‘Amit’ and ‘amit’ is different. After completing the job of adding the code, you can press Ctrl + F11 key to execute your program. As it is going to be executed, it will link all the different libraries, so it may take few seconds to show the result.

 

>

Just click on the button and you will see the text “CraveDevelopers” in orange color. If your text is different than mine, then you can look over our previous post of how to change the color of the text.

 

 

 
Leave a comment

Posted by on January 6, 2012 in Android

 

Hello World application


Hello World

  • Writing the Hello world message
  • Changing the Hello world message
  • Styling the Hello world message

Make a new Android project

New Android Project

Lets dive in and make a new project in Eclipse.

  • Start eclipse and goto: File > New > Other ( Ctrl+N )
  • Select Android project and click Next
  • Fill in a project name: HelloWorld
  • Choose a Build target: Android 2.2
  • Scroll down and fill in the Application name: Hello world
  • Fill in a package name: com.pxr.hello_world
  • Name the Activity: MainActivity
  • Click Finish

Here is a description of each field:
(From developers.android.com)

Project Name
This is the Eclipse Project name the name of the directory that will contain the project files.
Application Name
This is the human-readable title for your application the name that will appear on the Android device.
Package Name
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.Your package name must be unique across all packages installed on the Android system; for this reason, it’s important to use a standard domain-style package for your applications. The example above uses the “com.example” namespace, which is a namespace reserved for example documentation when you develop your own applications, you should use a namespace that’s appropriate to your organization or entity.
Create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android’s Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn’t need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.
Min SDK Version
This value specifies the minimum API Level required by your application. For more information, seeAndroid API Levels.

Android project file structure

project file structure

Now that you made your project you will see that eclipse made a new project folder in the Package explorer. THe picture on the right shows my new Hello world project . Here is a short explanation of the most important files/folders in the project.

src: This folder holds all the tutorial source files. As you can see in the image, Eclipse made 1 .java file. In this file is some basic code that is used to start up the Android app.

gen: All generated Java files reside here. When you open it you will see 1 file: R.java. the R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you’ve included in your project.

assets: Don’t really know what to put in here :) Maby leave me a comment ?

res: You can find 3 very important things here.

  1. All the  layout files ( main.xml )
  2. All resources ( thinks images most of the time icon.png)
  3. All string value’s / color values e.t.c ( strings.xml )

We will dive deeper into these files later on.

AndroidManifest.xml: This is the place where you specify the permission your app needs. We will not alter this file in this tutorial.

Writing text to the screen

Android Tutorial: Hello WorldAlready working ?

So we made a new project for this tutorial and we run by the file structure. When you run your project (Ctrl+F11) you will already see the Hello world message!! ( thanks to Eclipse ). But we want to understand why and how the app draws that onto the screen. Open up MainActivity.java.

MainActivity.java

package com.pxr.hello_world;

import android.app.Activity;

import android.os.Bundle;

public class MainActivity extends Activity {

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}


An Activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. The onCreate() method will be called by the Android system when your Activity starts  it is where you should perform all initialization and UI setup.

The most interesting line of code in this code exerpt is setContentView(R.layout.main);. With this line you tell the application to put build the screen with this file: res>layout>main.xml. Lets open that file.

Another code for using java

package com.javapapers.android;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class HelloWorld extends Activity {

/** Called when the activity is first created. */

Textview tv;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

tv=(Textview)findviewbyid(R.id.textview1)

tv.setText(“Hello World!”);

}}


Main.xml

This is the main layout for out tutorial project.


<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”>

<TextView android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:text=”@string/hello”

/>

</LinearLayout>


This layout file exists of 3 things:

  1. The xml declaration
  2. A LinearLayout
  3. A TextView

We want to take a closer look to the TextView. the android:text property contains a reference to another file. @stringis a reference to values>strings.xml. So i think we wanna open up that one :) .

Strings.xml

Our strings.xml file contains 2 string values.


<?xml version=”1.0″ encoding=”utf-8″?>

<resources>

<string name=”hello”>Hello World, MainActivity!</string>

<string name=”app_name”>Hello world</string></resources>

The first hello is the text that is displayed on the screen by calling @string/hello in the main.xml file. The other (app_name) is user for displaying the name of the app!

Well, that wasn’t exactly hard. Still strugling ? Just leave a comment down below.

Changing the Hello world message

Android development is easy!

Just by changing the text in strings.xml you can change the message that is printed on the screen. Lets change both values.

  • hello: Hey it worked =)
  • app_name: My first Android tutorial!

Result will be like the image to the right. You can change this text into whatever you like of course :)

Styling the Hello world message

Just one final adjustment. The text doesn’t look nice!  Lets change the layout like this

  • Put the text in the center of the screen.
  • Change the font
  • Change the color

Layout is changed in the Main.xml file. Open it up if you don’t have it open. After opening select the TextView element and replace it with the following:


<TextView android:layout_width=”fill_parent”android:layout_height=”fill_parent”

android:gravity=”center”

android:textSize=”25dip”

android:textColor=”@color/Gold”

android:text=”@string/hello”/>


After that make a new file in the folder values ( rightclick the folder – file ). Name the file: color.xml. We can use this xml file to store our color values. Paste the code below into the color.xml file:

<?xml version=”1.0″ encoding=”utf-8″?>

<resources>

<color name=”Gold”>#ffd700</color></resources>

After that: save and press Ctrl+F11 to run the project again!

veer well done!

 
Leave a comment

Posted by on January 3, 2012 in Practical

 

How to Setup Android Application Development on Eclipse


Android SDK provides the tools and APIs necessary to begin developing applications on the Androidplatform using the Java programming language. Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications.

This tutorial is intended for new developers that want to start developing Android applications using Eclipse IDE. To start develop, you have to install Java platform (JDK)  first and then  install the Eclipse,  Android SDK and the  Android Development Tool (ADT) plugin for Eclipse.

Download and Install JDK

Download and install the latest JDK (JDK 1.6 Update 18) from JDK download page

Download and Install Eclipse IDE

Download and install Eclipse Classic 3.5 (Galileo) from Eclipse download page. You can also use the  Java or RCP version of Eclipse.

Download and Install Android SDK Starter Package

The Android SDK starter package includes only a single component, the latest version of the SDK Tools. Included in that component is a tool called Android SDK and AVD Manager that you can use to download other components from the SDK repository site.

  • Download the latest Android SDK  starter package  from the SDK download page.
  • Unpack the archive to a suitable location on your machine. By default, the SDK files are unpacked into a directory named  android-sdk-<machine-platform> . For example, on Windows platform the directory will be android-sdk-windows.

Add Android Platforms to Your SDK

To add one or more Android platforms (for example, Android 1.6 or Android 2.1) to your SDK, use the Android SDK and AVD Manager, included in the SDK starter package. It is recommended  to download multiple platforms, so that you can build your application on the lowest version you want to support, but test against higher versions that you intend the application to run on.

  • Launch the Android SDK and AVD Manager on Windows by executing SDK Setup.exe at the root of the SDK directory. On Mac OS X or Linux, execute the android tool in the /tools/ folder.
  • On Available Packages menu, select the platforms to download (1.1 to 2.1).

  • Click Install Selected and then select Accept All to accept selected packages.
  • Click Install Accepted button to start download and install the selected packages.

Download and Install ADT Plugin

To install  the ADT Plugin, you can take advantage of the Eclipse remote update feature. By setting up a remote update site, you can easily download, install, and check for ADT updates. Alternatively, you can download the latest ADT to your development computer as a local site archive.

  • Launch Eclipse, then select Help –> Install New Software.

  • In Available Software dialog, click Add
  • Enter a name for the remote site (ex: Android Plugin) in the Name field and in the Locationfield, enter this URL:
    https://dl-ssl.google.com/android/eclipse/
    and then click OK. If you have trouble acquiring the plugin, you can try using ‘http’  instead of  ’https’  in the URL.

  • Select the checkbox next to Developer Tools, which will automatically select the nested toolsAndroid DDMS and Android Development Tools and then click Next.

  • On the next dialog, click Next to read and accept the license agreement and install any dependencies, then click Finish.
  • Restart Eclipse
  • To check whether the ADT has been installed correctly, try to create a new project by selectFile > New > Project., you shoud find Android Project listed on project wizard.

configuration of eclipse for android sdk

Select window menu and Go to Preferences option select

Manually install Android SDK

The previous step downloads the Android SDK automatically for you. You can also download the Android SDK manuallz from the Android homepage under Android SDK download. The download contains a zip file which you can extract to any place in your file system, e.g. I placed it under “c:\android-sdk-windows”. Avoid using spaces in the path name otherwise you may experience problems later.

You also have to define the location of the Android SDK in the Eclipse Preferences. In Eclipse open the Preferences dialog via Windows → Preferences. Select Android and enter the installation path of the Android SDK.

Click Apply you are found different SDK version

Install a specific Android version

The Android SDK Manager allows you to install specific versions of Android. Select Window → Android SDK Manager from the Eclipse menu.

Create an Android Emulator Device

The Android tools include an emulator. This emulator behaves like a real Android device in most cases and allows you to test your application without having a real device. You can emulate one or several devices with different configurations. Each configuration is defined via an “Android Virtual Device” (AVD).

To define an AVD open the “AVD Manager” via Windows → AVD Manager and press “New”.

Enter the following.

We can also select the box “Enabled” for Snapshots. This will make the second start of the virtual device much faster.

At the end press the button “Create AVD”.This will create the device and display it under the “Virtual devices”. To test if your setup is correct, select your device and press “Start”.

After (a long time) your device should be started.

Emulator Shortcuts

Obviously you can use the emulator via the keyboard on the right side of the emulator. But there are also some nice shortcuts which are useful.

Alt+Enter maximizes the emulator. Nice for demos.

Ctrl+F11 changes the orientation of the emulator.

F8 turns network on / off.

 

Tags: , , , ,

Download the Android SDK


Welcome Developers! If you are new to the Android SDK, please read the steps below, for an overview of how to set up the SDK.

If you’re already using the Android SDK, you should update to the latest tools or platform using the Android SDK and AVD Manager, rather than downloading a new SDK starter package. See Adding SDK Components.

Platform Package Size MD5 Checksum
Windows android-sdk_r16-windows.zip 29562413 bytes 6b926d0c0a871f1a946e65259984701a
installer_r16-windows.exe (Recommended) 29561554 bytes 3521dda4904886b05980590f83cf3469
Mac OS X (intel) android-sdk_r16-macosx.zip 26158334 bytes d1dc2b6f13eed5e3ce5cf26c4e4c47aa
Linux (i386) android-sdk_r16-linux.tgz 22048174 bytes 3ba457f731d51da3741c29c8830a4583

Here’s an overview of the steps you must follow to set up the Android SDK:

  1. Prepare your development computer and ensure it meets the system requirements.
  2. Install the SDK starter package from the table above. (If you’re on Windows, download the installer for help with the initial setup.)
  3. Install the ADT Plugin for Eclipse (if you’ll be developing in Eclipse).
  4. Add Android platforms and other components to your SDK.
  5. Explore the contents of the Android SDK (optional).

To get started, download the appropriate package from the table above, then read the guide to Installing the SDK.

 
 

ADT Plugin for Eclipse


In this document

  1. Revisions
  2. Installing the ADT Plugin
  3. Preparing for Installation
  4. Downloading the ADT Plugin
  5. Configuring the ADT Plugin
  6. Troubleshooting
  7. Updating the ADT Plugin
  8. Android Developer Tools

See also

Android Development Tools (ADT) is a plugin for the Eclipse IDE that is designed to give you a powerful, integrated environment in which to build Android applications.

ADT extends the capabilities of Eclipse to let you quickly set up new Android projects, create an application UI, add components based on the Android Framework API, debug your applications using the Android SDK tools, and even export signed (or unsigned) .apk files in order to distribute your application.

Developing in Eclipse with ADT is highly recommended and is the fastest way to get started. With the guided project setup it provides, as well as tools integration, custom XML editors, and debug ouput pane, ADT gives you an incredible boost in developing Android applications.

This document provides step-by-step instructions on how to download the ADT plugin and install it into your Eclipse development environment. Note that before you can install or use ADT, you must have compatible versions of both the Eclipse IDE and the Android SDK installed. For details, make sure to read Installing the ADT Plugin, below.

If you are already using ADT, this document also provides instructions on how to update ADT to the latest version or how to uninstall it, if necessary.

For information about the features provided by the ADT plugin, such as code editor features, SDK tool integration, and the graphical layout editor (for drag-and-drop layout editing), see the Android Developer Tools document.

Revisions

The sections below provide notes about successive releases of the ADT Plugin, as denoted by revision number.

For a summary of all known issues in ADT, see http://tools.android.com/knownissues.

 ADT 16.0.1 (December 2011)

Dependencies:

  • Eclipse Helios (Version 3.6) or higher is required for ADT 16.0.1.
  • ADT 16.0.1 is designed for use with SDK Tools r16. If you haven’t already installed SDK Tools r16 into your SDK, use the Android SDK Manager to do so.

Bug fixes:

  • Fixed build issue where the 9-patch could be packaged as normal bitmap in some cases.
  • Fixed minor issues in the Lint tool.
  • Fixed minor issues in the SDK Manager.

 ADT 16.0.0 (December 2011)

 ADT 15.0.1 (November 2011)

 ADT 15.0.0 (October 2011)

 ADT 14.0.0 (October 2011)

 ADT 12.0.0 (July 2011)

 ADT 11.0.0 (June 2011)

 ADT 10.0.1 (March 2011)

 ADT 10.0.0 (February 2011)

 ADT 9.0.0 (January 2011)

 ADT 8.0.1 (December 2010)

 ADT 8.0.0 (December 2010)

 ADT 0.9.9 (September 2010)

 ADT 0.9.8 (September 2010)

 ADT 0.9.7 (May 2010)

 ADT 0.9.6 (March 2010)

 ADT 0.9.5 (December 2009)

 ADT 0.9.4 (October 2009)

Installing the ADT Plugin

The sections below provide instructions on how to download and install ADT into your Eclipse environment. If you encounter problems, see the Troubleshooting section.

Preparing Your Development Computer

ADT is a plugin for the Eclipse IDE. Before you can install or use ADT, you must have a compatible version of Eclipse installed on your development computer. Check theSystem Requirements document for a list of Eclipse versions that are compatible with the Android SDK.

  • If Eclipse is already installed on your computer, make sure that it is a version that is compatible with ADT and the Android SDK.
  • If you need to install or update Eclipse, you can download it from this location:

http://www.eclipse.org/downloads/

The “Eclipse Classic” version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Additionally, before you can configure or use ADT, you must install the Android SDK starter package, as described in Downloading the SDK Starter Package. Specifically, you need to install a compatible version of the Android SDK Tools and at least one development platform. To simplify ADT setup, we recommend installing the Android SDK prior to installing ADT.

When your Eclipse and Android SDK environments are ready, continue with the ADT installation as described in the steps below.

Downloading the ADT Plugin

Use the Update Manager feature of your Eclipse installation to install the latest revision of ADT on your development computer.<>

Assuming that you have a compatible version of the Eclipse IDE installed, as described in Preparing for Installation, above, follow these steps to download the ADT plugin and install it in your Eclipse environment.

  1. Start Eclipse, then select Help > Install New Software….
  2. Click Add, in the top-right corner.
  3. In the Add Repository dialog that appears, enter “ADT Plugin” for the Name and the following URL for the Location:
  4. Click OK
https://dl-ssl.google.com/android/eclipse/

Note: If you have trouble acquiring the plugin, try using “http” in the Location URL, instead of “https” (https is preferred for security reasons).

  1. In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
  2. In the next window, you’ll see a list of the tools to be downloaded. Click Next.
  3. Read and accept the license agreements, then click Finish.

Note: If you get a security warning saying that the authenticity or validity of the software can’t be established, click OK.

  1. When the installation completes, restart Eclipse.

Configuring the ADT Plugin

After you’ve successfully downloaded the ADT as described above, the next step is to modify your ADT preferences in Eclipse to point to the Android SDK directory:

  1. Select Window > Preferences… to open the Preferences panel (Mac OS X: Eclipse > Preferences).
  2. Select Android from the left panel.

You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and click Proceed. You cannot continue with this procedure until you click Proceed.

  1. For the SDK Location in the main panel, click Browse… and locate your downloaded SDK directory.
  2. Click Apply, then OK.

Done! If you haven’t encountered any problems, then the installation is complete. If you’re installing the Android SDK for the first time, return to Installing the SDK to complete your setup.

Troubleshooting ADT Installation

If you are having trouble downloading the ADT plugin after following the steps above, here are some suggestions:

  • If Eclipse can not find the remote update site containing the ADT plugin, try changing the remote site URL to use http, rather than https. That is, set the Location for the remote site to:
  • If you are behind a firewall (such as a corporate firewall), make sure that you have properly configured your proxy settings in Eclipse. In Eclipse, you can configure proxy information from the main Eclipse menu in Window (on Mac OS X, Eclipse) > Preferences > General > Network Connections.
http://dl-ssl.google.com/android/eclipse/

If you are still unable to use Eclipse to download the ADT plugin as a remote update site, you can download the ADT zip file to your local machine and manually install it:

  1. Download the current ADT Plugin zip file from the table below (do not unpack it).
Name Package Size MD5 Checksum
ADT 16.0.1 ADT-16.0.1.zip 7000078 bytes 03a2a23650ddac128c8b9e8aaf0aa433
  1. Follow steps 1 and 2 in the default install instructions (above).
  2. In the Add Site dialog, click Archive.
  3. Browse and select the downloaded zip file.
  4. Enter a name for the local update site (e.g., “Android Plugin”) in the “Name” field.
  5. Click OK.
  6. Follow the remaining procedures as listed for default installation above, starting from step 4.

To update your plugin once you’ve installed using the zip file, you will have to follow these steps again instead of the default update instructions.

Other install errors

Note that there are features of ADT that require some optional Eclipse components (for example, WST). If you encounter an error when installing ADT, your Eclipse installion might not include these components. For information about how to quickly add the necessary components to your Eclipse installation, see the troubleshooting topic ADT Installation Error: “requires plug-in org.eclipse.wst.sse.ui”.

For Linux users

If you encounter this error when installing the ADT Plugin for Eclipse:

An error occurred during provisioning.
Cannot connect to keystore.
JKS

…then your development machine lacks a suitable Java VM. Installing Sun Java 6 will resolve this issue and you can then reinstall the ADT Plugin.

Updating the ADT Plugin

From time to time, a new revision of the ADT Plugin becomes available, with new features and bug fixes. Generally, when a new revision of ADT is available, you should update to it as soon as convenient.

In some cases, a new revision of ADT will have a dependency on a specific revision of the Android SDK Tools. If such dependencies exist, you will need to update the SDK Tools component of the SDK after installing the new revision of ADT. To update the SDK Tools component, use the Android SDK and AVD Manager, as described inAdding SDK Components.

To learn about new features of each ADT revision and also any dependencies on the SDK Tools, see the listings in the Revisions section. To determine the version currently installed, open the Eclipse Installed Software window using Help > Software Updates and refer to the version listed for “Android Development Tools”.

Follow the steps below to check whether an update is available and, if so, to install it.

  1. Select Help > Check for Updates.

If there are no updates available, a dialog will say so and you’re done.

  1. If there are updates available, select Android DDMS, Android Development Tools, and Android Hierarchy Viewer, then click Next.
  2. In the Update Details dialog, click Next.
  3. Read and accept the license agreement and then click Finish. This will download and install the latest version of Android DDMS and Android Development Tools.
  4. Restart Eclipse.

If you encounter problems during the update, remove the existing ADT plugin from Eclipse, then perform a fresh installation, using the instructions for Installing the ADT Plugin.

 
Leave a comment

Posted by on January 3, 2012 in ADT Plugin for Eclipse

 

Tags: , , , , ,

Components Of An Application


Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application’s overall behavior.

There are four different types of application components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

Here are the four types of application components:

Activities
An activity represents a single screen with a user interface. 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. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.
An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.
Services
A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. 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. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.
A service is implemented as a subclass of Service and you can learn more about it in the Service developer guide.
Content providers
A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user’s contact information. As such, any application with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.
Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see the Content Providers developer guide.

Broadcast receivers
A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. 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. Although broadcast receivers don’t display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a “gateway” to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.
A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see theBroadcastReceiver class.

A unique aspect of the Android system design is that any application can start another application’s component. For example, if you want the user to capture a photo with the device camera, there’s probably another application that does that and your application can use it, instead of developing an activity to capture a photo yourself. You don’t need to incorporate or even link to the code from the camera application. Instead, you can simply start the activity in the camera application that captures a photo. When complete, the photo is even returned to your application so you can use it. To the user, it seems as if the camera is actually a part of your application.

When the system starts a component, it starts the process for that application (if it’s not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application’s process. Therefore, unlike applications on most other systems, Android applications don’t have a single entry point (there’s no main() function, for example).

Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application. The Android system, however, can. So, to activate a component in another application, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

 

What Do You Mean By An Application?


Android applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.

Once installed on a device, each Android application lives in its own security sandbox:

  • The Android operating system is a multi-user Linux system in which each application is a different user.
  • By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them.
  • Each process has its own virtual machine (VM), so an application’s code runs in isolation from other applications.
  • By default, every application runs in its own Linux process. Android starts the process when any of the application’s components need to be executed, then shuts down the process when it’s no longer needed or when the system must recover memory for other applications.

In this way, the Android system implements the principle of least privilege. That is, each application, by default, has access only to the components that it requires to do its work and no more. This creates a very secure environment in which an application cannot access parts of the system for which it is not given permission.

However, there are ways for an application to share data with other applications and for an application to access system services:

  • It’s possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other’s files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
  • An application can request permission to access device data such as the user’s contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.
 

Android Architecture


Android is a software stack for mobile devices that includes an operating system, middleware and key applications.

The following diagram shows the major components of the Android operating system.

                        The main components of the Android architecture:

1. Applications: These are applications written in Java. Some of the basic applications include calendar, email client, SMS program, maps, making phone calls, accessing the Web browser, accessing your contacts list and others.

If you are an average user, this is the layer you will use most, rest all layers are used by Google programmers, developers and hardware manufacturers.

2. Application Framework: This is the skeleton or framework which all android developers have to follow. The developers can access all framework APIs and manage phone’s basic functions like resource allocation,  switching between processes or programs, telephone applications,  and keeping track of the phone’s physical location.

The architecture is well designed to simplify the reuse of components. Think of the application framework as a set of basic tools with which a developer can build much more complex tools.

3. Libraries: This layer consists of Android libraries written in C, C++, and used by various systems. These libraries tell the device how to handle different kinds of data and  are exposed to Android developers via Android Application framework. Some of these libraries include  media , graphics, 3d, SQLite, web browser library etc.

The Android runtime layer which includes set of core java libraries and DVM (Dalvik Virtual Machine) is also located in same layer.

4. Runtime Android: This layer includes set of base libraries that are required for java libraries.  Every Android application gets its own instance of Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently and it executes files in executable (.Dex) optimized for minimum memory.

5. Kernel – Linux: This layer includes Android’s memory management programs, security settings, power management software and several drivers for hardware , file system access, networking and inter-process-communication. The kernel also acts as an abstraction layer between hardware and the rest of the software stack.

                                                             

Android GUI Architecture


Android GUI is single-threaded, event-driven and built on a library of nestable components.The Android UI framework is organized around the common Model-View-Controller pattern.

The Model : The model represents data or data container. You can see it as a database of pictures on your device. Say, any user wants to hear an audio file, he clicks play button and it triggers an event in your app,  now the app will get data from data store or database and as per input and creates data to be sent back to the user. You can refer this data as Model.

The View: The View is the portion of the application responsible for rendering the display, sending audio to speakers, generating tactile feedback, and so on. Now as per above example, the view in a hypothetical audio player might contain a component that shows the album cover for the currently playing tune. User will always interact with this layer. User action’s on this layer will trigger events that will go to the application functions.

The Controller: The Controller is the portion of an application that responds to external actions: a keystroke, a screen tap, an incoming call, etc. It is implemented as an event queue. On User’s action, the control is passed over to controller and this will take care of all logic that needs to be done and prepare Model that need to be sent to view layer.

Android Activity Life cycle

  • onCreate()
  • onStop()
  • onPause()
  • onRestart()
  • onDestory()
  • onFreeze()

 
Leave a comment

Posted by on January 1, 2012 in Android Architecture

 

Tags: , , , , ,

Overview of Android OS


                                            

 Image

 

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.

Features

  • Application framework enabling reuse and replacement of components
  • Dalvik virtual machine optimized for mobile devices
  • Integrated browser based on the open source WebKit  engine
  • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLite for structured data storage
  • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • GSM Telephony (hardware dependent)
  • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
  • Camera, GPS, compass, and accelerometer (hardware dependent)
  • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE
 
Leave a comment

Posted by on January 1, 2012 in Overview of Android OS

 
 
Create your own website, free on WordPress.com.Create your own website.
Start free