In Eclipse, choose Run➪Run or press Ctrl+F11 to run the application.

137

Chapter 5: Coding Your Application

7. Choose your phone from the list and click the OK button.

This sends the application to your phone, and it launches it just as it would with the emulator. In a few seconds, the app should show up on your phone. You’ve now deployed the application to your phone. Reinstalling Your Application You may have noticed that installing your application to a physical device was fairly simple. In fact, after the device is set up to allow non-Market applications to be installed, you take virtually the same steps. Well, the same goes for reinstalling your application. You don’t have to do anything special to reinstall your application. When would you reinstall your application? Simple — you change something in the app and you need to test it again. Understanding the state of the emulator After the emulator is running, it’s running on its own. The emulator has no dependencies on Eclipse. In fact, you can close Eclipse and still interact with the emulator. The emulator and Eclipse speak to each other through the Android Debugging Bridge ADB. ADB is a tool that was installed with the Android Development Tools ADT. Doing the reinstallation The application reinstall process is fairly simple. To reinstall an application, perform the same steps that you would when you initially installed the application: Choose Run➪Run or press Ctrl+F11. Now that was easy. 138 Part II: Building and Publishing Your First Android Application Uh-oh: Responding to Errors You wrote perfect code, right? I thought so Well, I have a secret to tell: I don’t always write perfect code. When things don’t go as planned, I have to figure out what is going on. To help developers in these dire situations of random application crashes, the ADT provides some valuable tools to help debug your application. Using the Dalvik Debug Monitor Server The Dalvik Debug Monitor Server DDMS is a debugging tool that provides the following features among others: ✓ Port forwarding ✓ Screen capture ✓ Thread and heap information on the device ✓ LogCat provides dumps of system log messages ✓ Process and radio state information ✓ Incoming call and SMS spoofing ✓ Location data spoofing DDMS can work with an emulator and a connected device. DDMS is located in the Android SDK tools directory. In Chapter 1, you added the tools direc- tory to your path; therefore, you should be able to access DDMS from the command line. Why you should get to know DDMS Debugging is rarely fun. Thankfully, DDMS provides the tools necessary to help you dig yourself out of a hole of bugs. One of the most commonly used features in DDMS is the LogCat viewer, which allows you to view the output of system log messages from your system, as shown in Figure 5-9. This system log reports everything from basic information messages, which include the state of the application and device, to warning and error informa- tion. When you receive an Application Not Responding or a Force Close error on the device, it’s not clear what happened. Opening DDMS and reviewing the entries in LogCat can help identify, down to the line number, where the exception is occurring. DDMS won’t solve the problem for you darn it, but it can make tracking down the root cause of the issue much easier.