Once you have an Application started in Eclipse the obvious next step is testing it. This can be done one of two ways; either through an actual device you wish to test on, or by creating a virtual device. Here I’ll show you how to do both.
If you own an Android-based phone or tablet you can test your application on the device itself. This is far and away the most desirable way to test your program if you’re able. You will need to do four things in order to use this method:
- Set up your system to detect your device as an Android Debug Bridge: This will likely require you to install a USB driver, for details on your particular device and what to install, this link should be of assistance.
- Allow “USB Debugging” on your device: This is likely to be found somewhere like Settings > Applications > Development
- Allow “Unknown sources”: This will also be somewhere like Settings > Applications > Development and simply allows the installation of non-Market apps.
- Connect your device to the computer: Whatever device you have probably came with some kind of cable to connect to your machine so make sure you have that and then connect it up.
Once those steps are complete you should be able to simply press play in Eclipse and choose “Android Application” to see your app installed on your device.
Android Virtual Device
The other way of testing your application is to create an emulator that your app can run in. This method is prone to crashing, time-consuming to set up and your app will run MUCH slower than it would in reality…however it does mean you can test without an actual device if you wish. To set up a virtual device, click on the AVD button in Eclipse:
Then follow these steps:
- Click on “New…”
- Give your new AVD a simple name, something like “myavd”
- Choose the target platform (in my case 2.2)
- Enable “Snapshot”. This will help your AVD to load faster next time
- Click “Create AVD”
- Select your AVD from the list and click “Start…”
- In the “Launch Options” dialog leave the settings as is and select “Launch”
At this point you may want to go and paint the house, grow a tree, enter old age…basically the emulator can take an awfully long time to create. Some factors that may speed up this process include using a fast machine, not running Eclipse portably or just acquire a device to test on instead of using the emulator!
Once you’ve got a way to test your application you should be able to simply press the Play button in Eclipse and have it load and run! You should see the phrase “Hello World, StartActivity!” appear on the screen.
If you have any trouble just use the comments section below.