Powered By Blogger

Monday, July 16, 2012

Android-Simple Program


       Go to File>New>project and select Android project.
       Fill in the desired project name i.e. àhelloandroid. Next.
       The version of android will be checked by default. Next.
       Application name will be same as project name and package name à com.example.helloandroid. Finish.

Virtual emulator settings:
       In Eclipse, select Window > Android SDK and AVD Manager.
       Select Virtual Devices in the left panel.
       Click New....The Create New AVD dialog appears.
       Type the name of the AVD, such as "my_avd".
       Choose a target. The target is the platform (that is, the version of the Android SDK, such as 4.0.3) you want to run on the emulator. For this tutorial, choose the latest platform that you have installed and ignore the rest of the fields.
       Click Create AVD.
       Now project has been created on the left hand side panel you will have the project name folder. Explore it. Goto src>com.example.helloandroid. Open helloandroid.java file.
       It will have the following code.

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class helloandroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Edit it to..

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;  /** textview widget is added to show the text on blank screen*/

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");    /** the tab screen in our case the virtual emulator shows the given text*/
       setContentView(tv);

   }
}

Note: the things in bold letters are only the new lines to previous code. Save and Run the code.
  • A View is a drawable object used as an element in your UI layout, such as a button, image, or (in this case) a text label. Each of these objects is a subclass of the View class and the subclass that handles text is TextView.  
  • you create a TextView with the class constructor, which accepts an Android Context instance as its parameter. A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. The Activity class inherits from Context, and because your HelloAndroid class is a subclass of Activity, it is also a Context. So, you can pass this as your Context reference to the TextView.  
  • SetText will show the string content within the paranthases. And setContentView will show the result on emulator screen that is tv.



Android it all-intro


Hello, everybody is familiar to Android.
Android is a Linux-based operating system for mobile devices such as smart phones and tablet computers. It is developed by the Open Handset Alliance led by Google.
Programming Languages: core C, java, C++
Supported Platforms: ARM Processor, MIPS, X86
Kernel Type: Monolithic Modified Linux kernel
Android versions till today: 2.3 gingerbread, [3.0, 3.1, 3.2] honeycomb, 4.0 ice cream sandwich and the latest 4.1 jelly bean.
It needs knowledge of JAVA programming to make effective and attractive apps.
Procedure of installation:

Programs needed:
  1. Android starter package:Download from http://developer.android.com/sdk/index.html (recommended exe)
  2. JAVA JDK: Download from http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3-download-1501626.html (windows x86 32 bit-84.12 MB)
  3. ECLIPSE IDE: Download from http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.7.2-201202080800/eclipse-SDK-3.7.2-win32.zip


Carefully go through the following steps.
  • Install JAVA JDK first. After JDK installation, install Android starter package that you have downloaded first. 
  • Eclipse will be a zip file just extract it to windows drive and put the shortcut of eclipse.exe to desktop so that you can easily operate it from desktop. 
  • Now open Eclipse, select the work space as default(but remember it). In Eclipse IDE go to help>install new software (don’t use proxy settings for your browser otherwise this won’t work). 
  • A prompt will open. Here let me tell you we are installing ADT (Android Development Tools)plug-in into Eclipse IDE so that we can use android SDK manager from within Eclipse. Click add in the top right corner and enter name as “ADT plugin” and location as

Click OK. Note: If you have trouble acquiring the plugin, try using "http“ in the Location URL, instead of "https" (https is preferred for security reasons).
  • In the Available Software dialog, select the checkbox next to Developer Tools and click Next
  • In the next window, you'll see a list of the tools to be downloaded. Click Next. 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
  • When the installation completes, restart Eclipse. When you will restart eclipse you will get two icons for Android SDK manager and Android Virtual device manager in the upper panel (toolbar)of Eclipse IDE or in windows tab of IDE.
  • In eclipse, go to windows>Android SDK manager and the list of android platforms will be loading. It will show the tools and APIs and the status (installed or not). 
  • Choose any latest version i.e. 4.0.3 check box that has all six components (documentation, SDK platform, samples for SDK, ARM EABI v7 system image, Google APIs, Source for Android SDK). Click on install packages and it will automatically install the checked packages to your IDE platform. That’s it. You are set up with your android development environment.