geetha has posted 1 posts at DZone. View Full User Profile

Google Android Tutorial

06.03.2008
| 236537 views |
  • submit to reddit

Google has recently released the Android platform for developing mobile applications. The language used for developing Android programs is Java, but it is not Java Micro Edition.  No wireless application developer can ignore  Android. Google is the best known brand name, among the users of the web and Android comes from Google. 

I am presenting this hands-on tutorial, as a sequel to my j2me series. Adequate knowledge of core-java ,especially Event-handling, Swing and inner-classes is assumed. Though Android does not make use of Swing, it uses  similar ideas.

We can develop Android lessons and applications in Eclipse environment. Google have provided an Eclipse-plugin for Android. This is the popular method. Google has not given direct support to Netbeans. But some Netbeans users have developed a method for running Android in Netbeans . It is available at  http://undroid.nolimit.cz/. You can find more screenshots and guidance in http://eppleton.com/blog/.

We can develop Android lessons without using either Eclipse or Netbeans. The necessary command-line tools have been provided by Google. I found that using these command-line tools is easier than either Eclipse or Netbeans method. So, I am basing all the following lessons on these tools. I think, most readers will agree with my view, after they try this method as well as Eclipse method. The Android site at 'code.google.com/android' has already given step-by-step instructions about Android in Eclipse. You can also get more details with screen shots from  a wonderful website at www.tanguay.info/web/welcome.php titled 'Edward's Web Developer site'. He gives excellent guidance with plenty of screen shots 

The Android site lacks clarity about the command-line method. Hence, I think I am adding something useful by writing on the command-line method instead of simply repeating the material in Android site.
Let us start from the beginning. The first step is downloading the Android SDK (version m5-rc14, Feb-12, 2008). Android was released in November, 2007 . It has been revised in the Feb-2008 version.Some of the earlier examples may not work in the newer version.

I am working in Windows-2000 and so I downloaded the windows version. The supported platform in Windows is either Windows-XP or Vista.(Mac OS 10 & Ubuntu Linux are the other platforms mentioned). However, it works well in my Win-2000. It is advisable to have at least 512MB memory. The android SDK is a zip file. I unzipped it to C:\unzipped\android and later, I copied that folder to D:\android. If you want, you can simply copy it to another drive like G:\android also. In the following lessons D:\android is used.

If you want to develop using Eclipse, you must have installed either Eclipse3.2 or Eclipse3.3(Europa). I have tested with Eclipse3.2. No problem.It works. But, we require ADT  (ie) Android Development Tools plugin for Eclipse, if you are using Eclipse.You can get this plugin from http://code.google.com/android/adt_download. You have to be careful about the ADT version number.It is ADT-0.3.3.


As my present focus is on command-line method, let me begin straight away and give a simple demo.The procedure given here is common for all our experiments and so I will not be repeating it in each demo. So, please note it down carefully.

Demo 1 - TextBox

In my first demo, I will have a customary button and textbox ( called EditField in Android). When I click the button, I want the message "SUCCESS!" to be displayed in textbox. Just as an exercise, I am using two buttons and two textboxes.


The first step is to start the Emulator

cd to d:\android\tools

d:\android\tools>emulator

It will take a long time to get started. Do not be in a hurry. Wait till it gets fully started. And do not  close that window carelessly by mistake. In that case, you will have to start it again and wait for a long time again. Finally, we get the emulator screen
 

The second step is to give the following command, from another command window.

d:\android\tools>

activityCreator --out  demo                                   mypack.mydemos.demo

This means that my project is 'demo' and my package is 'mypack.mydemos'. A number of folders are created automatically by this command:

  • tools\demo\src
  • tools\demo\bin
  • tools\demo\res.  

We need to note  the src and res folders carefully. We will place the java source file in src folder and main.xml file in res\layout, overwriting any files that are generated automatically. For the moment, we can think of the res\layout folder as the one which decides the gui design. As in asp.net, flex etc, the gui details are specified in xml file. But how shall we write the XML file? by hand? Not too difficult .But....luckily, there is an open-source gui designer named 'DroidDraw' available in http://www.droiddraw.org/ .It is a nice tool and if you like it, you can send your appreciation to brendan.d.burns@gmail.com. He has given a simple tutorial too, on how to use this gui tool.

I downloaded this software from the above site. I unzipped it. ( any folder). When we click on the icon, we get the screen as given below.

Droid DrawDroid Draw

 

Drawing Canvas AreaDrawing Canvas Area

Toolbox & Blank AreaToolbox & Blank Area 

Thus we get a window, showing the drawing canvas on leftside and toolbox and a blank area in the rightside. ( for printing purpose, I have split them into two screens) as above.

Published at DZone with permission of its author, geetha ganesan.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Paul Bourdeaux replied on Thu, 2008/06/05 - 8:38am

Great article and tutorial.  My company has been digging into Android lately, and you have a lot of helpful links and info for developers who are just starting with it.  Thanks!

Musa Musa L replied on Mon, 2008/06/09 - 6:10am

Hello,

Great tutorial.. I am trying to run the example on openSuSE 10.3 with jdk6 update 6 and i keep on getting the following error message

Application error: mypack.mydemos

An error has occured in mypack.mydemos.

Unable to start activity ComponentInfo{mypack.mydemos/mypack.mydemos.demo}:java.lang.ClassCastException:Landroid/widget/TextView;. 

What do you think is going on? I followed the steps exactly as you outlined..

I'd appreciate any help 

Musa Musa L replied on Tue, 2008/06/10 - 2:15pm in response to: Musa Musa L

found the problem... i copied and pasted your java code directly without changing EditText to TextView. In main.xml, the textboxes are TextView objects not EditView. Made the changes and everything works as it should....

Kim Hoang replied on Mon, 2008/07/21 - 1:18pm

Our company is currently looking for 2 mobile apps engineers for an Android project.  Does anyone know anybody interested in working on this project?  It will be based out of Sunnyvale, CA.  Thanks.

shanmugavel .s replied on Tue, 2008/09/09 - 12:51pm

i created the helloworld program using command prompt,it builded sucessfullyand also i installed sucessfully . but there is no display in emulator .wats the problem,how to correct it.

william mensah replied on Thu, 2008/10/23 - 4:30pm

line 5:  xmlns:android="http://schemas.android.com/ apk/res

 

the space between .com/ apk causes errors. Just thought I'd throw it out there. Got me puzzled for a while.

Good tutorial though! Very helpful. Need one on databases though; that would be nice :). keep up the good work.

william mensah replied on Thu, 2008/10/23 - 4:32pm

my last post was with reference to Demo 2....fyi.

joby nk replied on Mon, 2008/12/29 - 7:02am

Hello,

           great tutorial, iam trying to this code in Eclipd IDE , the first two demos working fine,but the Demo-3

throws an error "Ticker.TickerListener  cannot be resolved to a type"  when we implements the demo class by Ticker.TickerListener  . why this error comes ,is there any other library need to link or anythng want to import.Hopfully expecting reply

Naina Kiran replied on Fri, 2009/01/16 - 3:41am

Hi Geetha,

This is Naina. I have recently started working on android. I have written 1 or 2 small applications. I went through the link, [url=http://geeth.ganesan.googlepages.com/android-tutorial]geeth.ganesan - ANDROID-TUTORIAL[/url]. I am trying to use the Spinner application written by you. I tried to run the same Spinner application on the android emulator using Eclipse IDE. But its not working. Iam getting the following exception error.

The application spin_and(process com.example.android.spin_and) has stopped unexpectedly. Please try again. Force Close.

I am not understanding where is the problem. I did not get any errors also. Please help me out. 


Thanks,

Naina

Rakesh sharma replied on Tue, 2009/03/03 - 3:34pm

im doing my final year project in IRTT college in Erode,tamilnadu.....plez tell a suggestion to develop an application in Android ........

padma bhujangaiah replied on Wed, 2009/04/08 - 8:45am in response to: joby nk

Hello Joby, I was going through the tutorial , I am also getting the same error for "Ticker.TickerListener cannot be resolved to a type" I was just wondering did you get the solution for your issue if so please let me know how did you resolve.

padma bhujangaiah replied on Wed, 2009/04/08 - 8:49am

Hello Madam, I was going through the tutorial , I am also getting the same error for "Ticker.TickerListener cannot be resolved to a type" . I didnot see any posts from you for the same issue which I read in the comments section . Is this is the right place to ask questions. If not please let me know where I should put my questions. By the way the XML DroidDraw and your tutorial helped me a learn how to write an andriod application. Thank you.

rajesh Vijayanadhan replied on Thu, 2009/07/02 - 6:23am

Hi,

I had creates a gallery with some images and its working fine for me.

Is there any way to put a seeker in the window for gallery.Is there any way to start a slide show(with gallery) when startActivity?

Please give me some suggestions...

 

Thanks And Regards,

Rajesh.V

Michael Maguire replied on Thu, 2010/05/13 - 5:14pm

The Spinner example has a space in the main.xml source:

xmlns:android="http://schemas.android.com/ apk/res/android"

 

which caused my version of the demo to crash each time it started up with LogCat error:

 

Binary XML file line #2: You must supply a layout_width attribute

Nagesh Golem replied on Fri, 2011/02/04 - 12:29am

Hello Experts,

 

I am new to android development, i am developing one application which needs to play an audio song to callee when call is lifted by callee, and automatically call has to be disconnected automatically when audio song playing completed . i tried to find in android API for any classes or methods to do this, but failed to find... please help me how to do this.. your answer could be helpful to me...please do reply Thank you in advance..

Amit Panchal replied on Fri, 2011/02/11 - 9:30am

nice article after reading your tutorial i also developed one application please have a look at this and give me your reviews and ratings: Talking Clock Regards, Amit Panchal Amitech Business Solutions

Vinod Verma replied on Wed, 2011/03/23 - 1:10am in response to: Kim Hoang

Hello I am developing a project for New York's Company based on spring Hibernate & JSF & also developing Android based application for my company if do you have any android based project then call me Thanks & Regards Vinod Verma +918109366080

Vinod Verma replied on Wed, 2011/03/23 - 1:16am in response to: shanmugavel .s

type following C:\Program Files\Android\android-sdk\tools\adb install C:\Workspace\applicationName\bin\applicationName.apk

Pasta Kare replied on Mon, 2011/04/18 - 8:17pm

I am still confused with the usage of javascript like the picture above, is there anything easier?
but this can add to the experience for me, maybe good to try.

Reza Gholami replied on Thu, 2011/08/18 - 11:57am in response to: Kim Hoang

Hi Kim,

I've seen your post about mobile app engineer for an Android project. I'm interested and have developed Java based apps in many frameworks such as SaaS and financial projects and recently Google Android apps on NetBeans

IDEs(6.8, 6.9,6.9.1, 7, and latest version7.0.1) and Eclipse tools and platforms. Furthermore, I'm skilled developper in Web EE  and MVC architecture including JSP/Servlet and JSF and Struts frameworks.

I look forward to hearing from you.

Please email (rgholami@comcast.net) or call me (925) 381-8994.

Thank you, Reza Gholami

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.