Intro/tutorial-extra-credit
From Android中文网
目录 |
[编辑] 入门指引: 额外的练习(Extra Credit)
In this exercise, you will use the debugger to look at the work you did in Exercise 3. This exercise demonstrates:
How to set breakpoints to observe execution How to run your application in debug mode [Exercise 1] [Exercise 2] [Exercise 3] [Extra Credit]
在本练习中,你将使用调试器观察在记事本练习3中所完成的程序。 本练习示范了如下内容:
- 如何设置断点来观察程序执行过程
- 如何在调试模式下运行你的程序
[Exercise 1] [Exercise 2] [Exercise 3] [Extra Credit]
[编辑] Step 1
Using the working Notepadv3, put breakpoints in the code at the beginning of the onCreate(), onPause(), onFreeze() and onResume() methods in the NoteEdit class (if you are not familiar with Eclipse, just right click in the narrow grey border on the left of the edit window at the line you want a breakpoint, and select Toggle Breakpoint, you should see a blue dot appear).
打开可用的 Notepadv3 项目,在 NoteEdit 类的如下方法的第一行设置断点,这些方法是 onCreate(), onPause(), onFreeze() and onResume()。(对Eclipse不熟悉也没关系,只需在代码编辑窗口左侧的窄条上,对应到你想设置断点的那一行,右键单击,然后再弹出菜单中选择“Toggle Breakpoint”,就能看到设置了一个蓝色的断点)
[编辑] Step 2
Now start the notepad demo in debug mode:
Right click on the Notepadv3 project and from the Debug menu select Debug As -> Android Application. The Android emulator should say "waiting for debugger to connect" briefly and then run the application. If it gets stuck on the waiting... screen, quit the emulator and Eclipse, from the command line do an adb kill-server, and then restart Eclipse and try again.
现在使用调试模式启动 notepad 示例:
- 在 Notepadv3 项目上右击,然后从弹出菜单中选择 Debug As -> Android Application。
- Android 手机模拟器将短暂的显示一下 “waiting for debugger to connect”,然后开始运行程序。
- 如果窗口长时间显示 waiting... 并停在那里,退出手机模拟器和 Eclipse,从命令行运行 adb kill-server 命令,然后重新启动 Eclipse 来一次。
[编辑] Step 3
When you edit or create a new note you should see the breakpoints getting hit and the execution stopping.
当编辑或创建新语句后,你将发现程序执行到断点那里并高亮显示,然后停在那里。
[编辑] Step 4
Hit the Resume button to let execution continue (yellow rectangle with a green triangle to its right in the Eclipse toolbars near the top).
点击工具栏上的 Resume 按钮让这次运行继续执行下去(就是在 Eclipse 靠近顶部的工具栏上,图标是黄色矩形右侧有个带个绿色三角形的那个按钮)。
[编辑] Step 5
Experiment a bit with the confirm and back buttons, and try hitting home and making other mode changes. Watch what lifecycle events are generated and when.
The Android Eclipse plugin not only offers excellent debugging support for your application development, but also superb profiling support. If your application is running too slow, this can help you find the bottlenecks and fix them.
在手机模拟器上测试一下 confirm 和 back 键,然后试着点击 home 键 and making other mode changes。注意观察都发生了哪些应用进程生命周期的事件,以及在什么时间发生的。
Android 的 Eclipse 插件不仅为应用开发提供了极好的调试支持,而且提供了超一流的性能分析支持。如果你的程序运行起来很慢,它可以帮你找到瓶颈并且修正问题。
返回入门指引主页面...
