Game Development Reference
In-Depth Information
The dialog shows all the running emulators and currently connected devices, as well as all
other AVDs not currently running. You can choose any emulator or device on which to run
your application. Note the red × beside the connected device. This usually indicates that the
application won't run on this device because its version is lower than the target SDK version we
specified (14 versus 15 in this case). However, because we specified a minimum SDK version of
3 (Android 1.5), our application will actually work on this device as well.
Debugging and Profiling an Application
Sometimes your application will behave in unexpected ways or crash. To figure out what exactly
is going wrong, you want to be able to debug your application.
Eclipse and ADT provide us with incredibly powerful debugging facilities for Android
applications. We can set breakpoints in our source code, inspect variables and the current stack
trace, and so forth.
Usually, you set breakpoints before debugging, to inspect the program state at certain points
in the program. To set a breakpoint, simply open the source file in Eclipse and double-click
the gray area in front of the line at which you want to set the breakpoint. For demonstration
purposes, do that for line 23 in the HelloWorldActivity class. This will make the debugger stop
each time you click the button. The Source Code view should show you a small circle in front
of that line after you double-click it, as shown in Figure 2-14 . You can remove breakpoints by
double-clicking them again in the Source Code view.
Figure 2-14. Setting a breakpoint
Starting the debugging is much like running the application, as described in the previous section.
Right-click the project in the Package Explorer view and select Debug As ➤ Android Application.
This creates a new Debug configuration for your project, just as in the case of simply running the
application. You can change the default settings of that Debug configuration by choosing Debug
As ➤ Debug Configurations from the context menu.
Note Instead of going through the context menu of the project in the Package Explorer view, you
can use the Run menu to run and debug applications and to get access to the configurations.
 
 
Search WWH ::




Custom Search