Logcat
Dump a system message log. These messages include the stack trace when the simulator throws an error.
Android log
A logging class used to write messages to log files on the simulator. If you run logcat on ddms, you can view messages in real time. In yourCodeAdd several log writing method calls.
To use the log class, you only need to call log. V () (detailed), log. D () (Debug), log. I () (Information), log. W () (warning) or log. E () (error), select the corresponding method based on the log information you want
Log. I ("myactivity", "myclass. getview ()-requesting item number" + position) You can use logcat to read this information.
Traceview
Android can save a log to record the called method and the number of times the method is called. With traceview, you can view the log file on a graphical interface.
ADB
Android debugging bridge (ADB) is a versatile tool that helps you manage the status of devices or simulators.
Android command: You can publish the android command on the command line or script on your development machine. The usage is as follows:
ADB [-d |-E |-S <serialnumber>] <command>
Go to shell: ADB Shell
Query Simulators/device instances
ADB devices lists the serial numbers and statuses of simulators.
Send commands to specific Simulators/device instances
If multiple Simulators/device instances are running, you must specify a target instance when releasing the ADB command. To do this, use the-s option command. The-s option used is
ADB-S <serialnumber> <command>
For example, DB-s emulator-5556 install helloworld.apk
Install software:
ADB install <path_to_apk>
Import or copy files from Simulators/devices
You can use the adbpull and push commands to copy files to or from a data file of a simulator/device instance. The Install command only copies a .apk file to a specific location. Different from the command, the pull and push commands allow you to copy arbitrary directories and files to any location of a simulator/device instance.
Copy a file or directory from a simulator or device and use the following command ):
ADB pull <remote> <local>
Copy the file or directory to the simulator or device and run the following command)
ADB push <local> <remote>
In these commands, <local> and <remote> indicate the path to the target file/directory on the development machine (local) and simulator/device instance (remote) respectively.
The following is an example ::
ADB push foo.txt/sdcard/foo.txt
Query log ADB logcat
Stopping the ADB Server
In some cases, you may need to terminate the android debugging system and restart it. For example, if the android debugging system does not respond to a command, you can terminate the server and restart it. This may solve this problem.
You can use kill-server to terminate the ADB server. You can use ADB to issue the start-server command to restart the server.
Settings for debugging and testing on devices
Android provides numerous settings for easier debugging and testing.Program. To go to the development settings page, go to the simulatorDev tools> development settings. The settings page has the following options:
-
- Debug app: Select the program to debug. You do not need to associate it with the debugger, but setting this value has two effects:
- During debugging, If you suspend a breakpoint for a long time, this setting will prevent android from throwing an error.
- This setting allows you to select the "Wait For Debugger" option so that the program can be started only after the debugger is associated.
-
- Wait for Debugger: Blocks the loading of the selected program until a debugger is associated, so that you can set breakpoints in oncreate (). This is very important for debugging the startup process of an activity. When you change this option, the instance of any running program will be terminated. You can select this option only when you select a debug program in the preceding options. You can also add waitfordebugger () in the code to implement the same function.
-
- Immediately destroy activities: Tells the system to destroy an activity once it is stopped (for example, when Android releases memory ). This is very useful for testing code onfreeze (bundle)/oncreate (Android. OS. Bundle), otherwise it will be more difficult. If your program is not saved, selecting this option may cause many problems.
-
- Show screen updates: A pink rectangle will flash on any screen section being re-painted. This is necessary to find unnecessary screen painting.
- Show CPU usage: The CPU information is displayed at the top of the screen, showing how many CPU resources are being used. The red bar above shows the total CPU usage, and the green bar below it shows the CPU usage time on the screen. Note: you cannot disable this function once you enable it before restarting the simulator.
-
- Show screen FPS: Displays the current frame rate. This is very useful for viewing the total frame rate reached by the game. Note: you cannot disable this function once you enable it before restarting the simulator.
-
- Show background: When no activity screens is visible, a background mode is displayed. Generally, it does not appear, but it only appears during debugging.
The set options remain valid after the simulator restarts. If you want to cancel the set options, you must restart the simulator after canceling the settings to take effect.
Important debugging tips
Quick stack dump
To get a stack dump on the simulator, you can log in through the ADB shell, use "Ps" to find the process you want, and then "Kill-3 ",
The stack trace information is recorded in the log file.
Display useful information on the simulator Screen
A device can display useful information such as CPU utilization or edge highlighting in the repainting area. You can enable or disable these functions in the development settings window.
Obtain system status information (dumpstate) from the simulator)
You can use the Dalvik debug monitor service tool to obtain dumpstate information.
Obtain the program status information from the simulator (dumpsys)
You can use the Dalvik debug monitor service tool to obtain dumpsys information.
Obtain wireless connection information
You can use the Dalvik debug monitor service tool to obtain wireless connection information. InDeviceSelect "Dump radio state"
Log Record tracking data
You can call Android. OS. Debug. startmethodtracing () in an activity to use logs to record method calls and other trace data.
Log Record Radio Data
By default, radio information is not recorded in the system (because the data volume is huge ). However, you can use the following command to enable the radio record ADB shelllogcat-B radio
Run ADB
Andoid comes with a tool named ADB, which is powerful and can move and synchronize files to the simulator and forward ports. Run a Unix shell on the simulator.
Get the screen from the simulator
Dalvik debug monitor server (ddms) can obtain the screen from the simulator
Use the debugging help class
Android provides help classes such as util. log and debug for developers' convenience.
How to run a program through the command line
reference: http://www.javaeye.com/topic/201856 http://www.javaeye.com/topic/149227
Go to Shell
Reference c: \ Documents ents and Settings \ mawenjian> ADB Shell
Let's take a look at the help of the command. Reference # Am-help
Am-help
Error: Unknown command:-help
Usage: am [Start | instrument]
Am start [-A <action>] [-D ] [-T <mime_type>]
[-C <Category> [-C <Category>]...]
[-E <extra_key> <extra_value> [-E <extra_key> <extra_value>...]
[-N <component>] [-D] [<URI>]
Am instrument [-E <arg_name> <arg_value>] [-P <prof_file>]
[-W] <component>
Okay. Try to start the browser. Reference # Am start-N com. Google. Android. Browser/COM. Google. Android. browser. browseractivity
Am start-N com. Google. Android. Browser/COM. Google. Android. browser. browseractivity
Starting: intent {comp = {com. Google. Android. Browser/COM. Google. Android. browser. browseractivity }}
OK.
Try the following command: Reference # Am start-A Android. Intent. Action. View-D http://mwjian.javaeye.com
Am start-A Android. Intent. Action. View-D http://mwjian.javaeye.com
Starting: intent {Action = Android. Intent. Action. View data = http://mwjian.javaeye.com}
# Am start-A Android. Intent. Action. Call-D Tel: 88888888
Am start-A Android. Intent. Action. Call-D Tel: 88888888
Starting: intent {Action = Android. Intent. Action. Call DATA = Tel: 88888888}
# Am start-A Android. Intent. Action. all_apps
Am start-A Android. Intent. Action. all_apps
Starting: intent {Action = Android. Intent. Action. all_apps}
# Am start-A Android. Intent. Action. View GEO: 0, 0? Q = Shanghai
Am start-A Android. Intent. Action. View GEO: 0, 0? Q = Shanghai
Starting: intent {Action = Android. Intent. Action. View data = GEO: 0, 0? Q = Shanghai}
reference: Android manual www.cnblogs.com/jacktu omnipotent g.cn