Prerequisites: check out the android developer guide
As a "java challenged" person myself, I had no eclipse or java SDK on my computer.
So I got everything I needed:
You should check this page out if you want to know how to install the ADT Plugin for eclipse.
Now the next thing everybody says you should do is create an "Android Virtual Device" (AVD). This will allow you to run/debug your application on your machine. That is, you won't download your application on a real android phone, like the one you have on your desk right now! Because let's face it, you should at least have an Android Phone if you want to write software for one!
Creating the AVD is not a big deal, you just use Eclipse. Go to Window->AVD Manager and click New. Nothing too difficult, is it?
Next, the easiest part. Choose File->New->Project->Android Project. This will create a mock Android project, which you'll tweak a bit to display your message. Just override the "onCreate" method with this one:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
*you'll notice this only adds a couple of lines to the original method
![]() |
The code for "Hello World" application, just like in all the examples on the net |
Assuming you've written your "Hello World" 2 lines of code, you'd want to run the application in your newly set up AVD. Just use CTRL-F11 or choose Run->Run from the menu.
For many of us, and I can not stress this enough ->for me, this part was where I got stuck. The simulator started up no problem, up to the part with the Android flashing logo. And this is where it hung. I waited for about ten minutes, then I switched machines. I did everything from scratch, hoping to get it right a second time on this DIFFERENT machine.
It didn't work. Same problem.
So I did my way!
No just mine, but most of the people out there who write code for Android. I just used my real Android powered phone.
It sounded scary at first, but is was actually pretty easy to get it working. Just follow these steps:
- Set up your device to allow it to be used as a development tool. Go to Settings->Applications
- choose to "Allow installation of non-Market applications"
- go to "Development" and choose to use "Debug mode when USB is connected".
- connect your Android phone to the computer using your USB cable.
- if you need to install the ADB driver for your phone, just do a search on google on how to do just that: search for 'adb driver for' (add your phone model)
- do a quick test to confirm your device is available: using command prompt, go to "C:\Program Files (x86)\Android\android-sdk\platform-tools" and call "adb device". If you see anything listed after that, then that means your device is all set up and ready to go. Your platform tools path might be different than mine, but only you know that.
If you made this far, you are both perseverent and lucky, just like me! Congratulations, you can now use eclipse to run your application on your Android device. Just hit CTRL+F11 and check your phone. It should already be running your app!
![]() |
"Hello World" application on Android Actual device screen capture |
No comments:
Post a Comment