Emulator profiles

At this point, our sample application, the Android Tip Calculator, has compiled successfully. We now want to run our application in the Android Emulator.

If you have had any trouble building the sample application, now would be a good time to go back and clear up any syntax errors preventing the application from building. In Eclipse you can easily see errors because they are marked with a red x next to the project source file and on the offending line(s). If you continue to have errors, make sure that your build environment is set up correctly. Refer to appendix A of this book for details on configuring the build environment.

Our approach is to create a new Android Emulator profile so we can easily reuse our test environment settings. Our starting place is the Open Run Dialog menu in the Eclipse IDE, as shown in figure 2.14. As new releases of Eclipse become available, these screen shots may vary slightly from your personal development environment.

We want to create a new launch configuration, as shown in figure 2.15. To begin this process, highlight the Android Application entry in the list to the left, and click the New Launch Configuration button, shown circled in red in figure 2.15.

We now want to give our launch configuration a name that we can readily recognize. We are going to have quite a few of these launch configurations on the menu, so give the name something unique and easy to identify. The sample is titled Android Tip Calculator, as shown in figure 2.16. There are three tabs with options to configure, the first allowing the selection of the project and the first Activity in the project to launch.

iff ©

CtrH-FLl

Fll

Rut History

Pun Ai

I Op**1 Run Dialog.,,

Debug History

Debug As

^Open Debug Dialog...

All References...

Gtr|+SWt4W

tyVMxh

(^Inspect

0trl+5bfft+I

0 Display

Qrl+Sblft+O

^Enec

Q*l+U

Force RejUurt

Alt+Strft+F

Step Into Selection

^External Tools

»

© Toggle Breakpoint

Ctrl+Shift+e

© Toggle Line Breakpoint

o Toggle Method Breakpoint

^ Toggle Watchpoint

X Skip All Sreakponts

S^Rerftcivi All Breakpoints

J Add lava Exception Breakpoint..

0 Acid Class Load Breakpoint...

Figure 2.14 Creating a new launch configuration for testing our Android application

Figure 2.14 Creating a new launch configuration for testing our Android application

Figure 2.15 Select the Android Application run template.
Figure 2.16 Setting up the Android Emulator launch configuration

The next tab permits the selection of the desired skin, which includes the screen layout, the network speed, and the network latency. In addition, any command-line parameters desired can be passed through to the emulator, as shown in figure 2.17. When writing Android applications, keep in mind that the application may be run on different size screens, because not all devices have the same physical characteristics. This setting in the Android Emulator launch configuration is a great way to test an application's handling of different screen sizes and layouts.

The third tab permits us to put this configuration on the favorites menu in the Eclipse IDE for easy access, as shown in figure 2.18. We can select Run and/or Debug. Let's make both selections, since it makes for easier launching when we want to test or debug the application.

We're now ready to start the Android Emulator to test our Tip Calculator application, so we select our new launch configuration from the favorites menu, as shown in figure 2.19.

The Android Tip Calculator should now be running in the Android Emulator! Go ahead; test it out. But wait, what if there is a problem with the code but we're not sure where? It's time to have a brief look at debugging an Android application.

Emulator Zurich panmtarj! Screen 5i»: |HVGA j]

network Speed

NetworkUtency: |tione |

Additional Emulator command Line ootims

Figure 2.17 Selecting the operating characteristics of the Android Emulator

Figure 2.18 Adding this launch configuration to the toolbar menu

§= Java - ChapterZ/src/com/manning/iinlockingandropd/CltapterTwo.java -

Fit tit Sour« Retain Nyngatî Se»ch Proi«t Run windw> Help

§= Java - ChapterZ/src/com/manning/iinlockingandropd/CltapterTwo.java -

Fit tit Sour« Retain Nyngatî Se»ch Proi«t Run windw> Help

Package Explorer U

Ci 1 Chafer 1 Sample Q 2 Chapter 1 Example

- 1 Ë % 1 . *

9 lc? AndroidCbapteri a Uê AndroidChapfcerlExi >1 tS AndroidChaptCrtSflf

Ö-^HHBBI

0 3 Android Tip Calculator

Run As * (J Open Run Dialog.. . Organize Favorites.. é

Figure 2.19 Starting this chapter's sample application, Android Tip Calculator

Figure 2.19 Starting this chapter's sample application, Android Tip Calculator

0 0

Post a comment