Now that you have an Android emulator and a debug configuration, you can run your first app. Click SalutonMondo, the top item in the Package Explorer, and then click the bug icon in the Eclipse toolbar.
The Android emulator loads in its own window. This can take a minute or more, so wait patiently as the fake phone boots up. (The emulator is so slow to load it gives you time to ponder this Chinese proverb: “The oxen are slow but the earth is patient.”)
The emulator displays “Saluton Mondo!” as the text and title bar of the app, as shown in Figure 24.7. Controls enable the emulator to be used like a phone, but with a mouse instead of your finger. Click the back button to close the app and see how the Android device is emulated.
An emulator can do many of the things a real device can do, including connect to the Internet if the computer has an active connection. It also can receive fake phone calls and SMS messages.
Because it’s not a fully functional device, the apps that you develop must be tested on actual Android phones and tablets.
If you can connect an Android phone (or other device) to your computer using a USB cord, you should be able to run the app if the phone is set in debugging mode. Apps developed with the Android SDK can be deployed only on a phone in this mode.
On the phone, enter this mode by choosing Home, Settings, Applications, Development. The Development settings are displayed. Choose the USB debugging option.
Next, in Eclipse, follow these steps:
1. Choose Run, Debug Configurations. The Debug Configurations window opens.
2. Click the Target tab in the right pane to bring it to the front.
3. Change Deployment Target Selection Mode from Automatic to Manual.
4. Click Apply and Close.
Connect your Android phone with the USB cord. An Android bug icon should appear on the bar at the top of the screen. If you drag this bar down, you should see the message “USB Debugging Connected.”
Back in Eclipse, click the bug icon in the toolbar. The Android Device Chooser dialog opens (see Figure 24.8).
If the Android phone has been detected, it appears in the top table in Figure 24.5 under the Choose a Running Device option.
Select this option, click the device, and click OK. The app runs on the phone as it did on the emulator.
Like the first program you wrote in Java back in Hour 2, the first app you created on Android is exceptionally unexceptional. The next project is more ambitious.
3.133.127.161