Wednesday, February 23, 2011

Quick Tip: Simple Debugging Android Apps with Logcat

Simple Debugging

The Android Debug Bridge (adb) is included as part of the Android SDK. One of the most powerful tools it features is the ability to view log messages from the Android Operating System and various android applications.

As part of setting up the Android sdk, you should already have ADB in your path variable. To use logcat, simply open up a terminal window, and type the following

adb logcat

You are now presented with continuously updating output of the most recently logged data. Pressing Ctrl+C will exit the logcat application.

Screenshot of adb logcat running in Windows

If an application is crashing, force closing, often times you can use the logcat information to find out what went wrong.

If you want to log custom information for your app, just use the following code.

Log.w(String tag, String message)

and be sure to include the following import at the top of your file:


import android.util.Log;




One Final Tip

Sometimes it is easy for a message to get lost in the log. If you really want to make a message stand out, you can surround it by several newlines. The following code shows this technique

Log.w("MyAPP", "\n\n  Important message \n\n");

No comments:

Post a Comment