Android Debugging Tools and methods

Source: Internet
Author: User
Tags stack trace

Transferred from: http://www.cnblogs.com/feisky/archive/2010/01/01/1637566.html

Logcat

Dump a log of system messages. These messages include the stack trace when the emulator throws an error.

Android Log

A logging class that is used to write messages to the log file on the emulator. If you run Logcat on DDMS, you can view the messages in real time. Add several calls to the Write log method in your code.
In order to use the Log class, you only need to call LOG.V () (verbose), LOG.D () (Debug), LOG.I () (information), LOG.W () (warning), or LOG.E () (Error), Choose the appropriate method based on the log information you want to get

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 method being called and the number of times the method has been called, through TraceView you can view the log file in a graphical interface.
adb

The Android Debug Bridge (ADB) is a versatile tool that can help you manage the state of your device or emulator.

Issue Android Commands: You can publish Android commands on the command line or script on your development machine using the method:

adb [-d|-e|-s <serialnumber>] <command>

Enter SHELL:ADB Shell

Query Simulator/Device instance
ADB devices lists the simulator serial number and status

Send commands to a specific simulator/device instance
If more than one emulator/device instance is running, you need to specify a target instance when you publish the ADB command. To do this, use the-s option for the command. The-s option in use is
Adb-s <serialNumber> <command>
such as: db-s emulator-5556 install helloworld.apk

Install the Software:
ADB install <path_to_apk>

Copy or copy files from simulator/device
You can use the Adbpull, push command to copy files to a data file for an emulator/device instance or to copy from a data file. The install command copies only one. apk file to a specific location, unlike the pull and push commands that allow you to copy arbitrary directories and files to any location on an emulator/device instance.
To copy a file or directory from a simulator or device, use the following (life):
ADB pull <remote> <local>
To copy a file or directory to an emulator or device, use (command below)
ADB push <local> <remote>
In these commands, <local> and <remote> refer to the path to the destination file/directory on their own development machine (local) and simulator/device instance (remote)
Here's an example:
ADB push Foo.txt/sdcard/foo.txt

Query log adb logcat

Stopping the ADB Server
In some cases, you may need to stop the Android debugging system from running and then restart it. For example, if the Android debugging system does not respond to commands, you can terminate the server and then restart it, which may solve the problem.
Use Kill-server to terminate ADB server. You can use ADB to issue start-server commands to restart the server.

Settings for debugging and testing on the device

Android offers a multitude of settings that make it easier for you to debug and test programs. To enter the Development Settings page, go to dev Tools > Development Settingsin the simulator. The following options are available on the Settings page:

  • Debug App: Select the program you want to debug. You do not need to set it to be associated to the debugger, but setting this value has two effects:
    • If you pause at a breakpoint for too long during debugging, this setting prevents Android from throwing an error
    • This setting allows you to select the "Wait for debugger" option so that the program starts only after the debugger is associated.
  • Wait for Debugger: Blocks the loading of the selected program until it has a debugger association, so you can set breakpoints in OnCreate (), which is important for debugging an activity's startup process. When you make changes to this option, any instances of the running program are terminated. You can only select this option by selecting a debugger in the options above. You can also add Waitfordebugger () to the code to achieve the same functionality.
  • Immediately Destroy Activities: tells the system to destroy the activity once an activity has stopped (for example, when Android frees up memory). This is useful for testing code Onfreeze (Bundle)/oncreate (android.os.Bundle), otherwise it can be difficult. If your program does not have a saved state, choosing this option will probably cause a lot of problems.
  • Show Screen Updates: A pink rectangle is flashed on any sections that is being redrawn. This is necessary to find unnecessary screen drawing.
  • Show CPU usage: Displays CPU information at the top of the screen, showing how much CPU resources are being used. The upper red bar shows the total CPU usage, and the green bar below it shows the CPU time spent on compositing the screen. Note: You cannot turn off the emulator once you have it turned on before restarting it.
  • Show Screen FPS: Displays the current frame rate. This is useful for viewing the total frame rate that the game achieves. Note: You cannot turn off the emulator once you have it turned on before restarting it.
  • Show background: Displays a background mode when no activity screens visible. Generally, it will not appear, only in the debug time.

The SET option is still valid after the emulator restarts, and if you want to cancel the setting, restart the emulator after the setting is canceled to take effect.

Important Debugging Tips

Fast Stack Dump

To get a stack dump on the emulator, you can log in with 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 emulator screen

Useful information such as CPU utilization or highlighting the edges of redrawn areas can be displayed on the device, which can be turned on or off in the Development Settings window.

Obtaining system state information from the emulator (dumpstate)

You can obtain dumpstate information by Dalvik the Debug Monitor Service tool.

Getting program status information from the emulator (Dumpsys)

You can obtain Dumpsys information by Dalvik the Debug Monitor Service tool.

Get Wireless connection Information

You can get wireless connection information through the Dalvik Debug Monitor Service tool. On the Device menu, select "Dump Radio State"

Log record tracking data

You can use the log to record method calls and other trace data in one activity by calling Android.os.Debug.startMethodTracing ().

Log Record Radio Data

By default, radio information is not recorded in the system (because of the large amount of data). However, you can use the following command to open the radio record ADB shelllogcat-b Radio

Run adb

The andoid comes with a tool called ADB, which is powerful and can move and synchronize files to the emulator, forwarding port. Run a Unix shell on the emulator.

Getting the screen from the emulator

Dalvik Debug Monitor Server (DDMS) can get the screen from the emulator

Using the Debug helper class

Android provides helper classes such as Util.Log and debug for the convenience of developers

How to run a program on the command line

Reference: http://www.javaeye.com/topic/201856 http://www.javaeye.com/topic/149227

Enter the shell

Referencing C:\Documents and settings\mawenjian>adb shell


Take a look at the command's help

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 starting the browser.

Ref # 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, it worked.
Let's 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}

This article refers to: Android manual www.cnblogs.com/jacktu Magnum g.cn

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.