简体   繁体   中英

Android Debugging?

What is the best way to debug an android application? Every once in a while the application crashes, an it says application has stopped unexpectedly, it never says why it crashes, or where in my code, what's the bet way to find the reason for crashes, and exceptions?

Your best approach is to include a bug and crash reporting service in your app. A good example is Instabug which can deliver all users crashes automatically to the product's dashboard in the background as soon as one occurs.

Reports are combined in one dashboard and they give you insights about crashes on each app version, crash severity, and more.

Every crash report also includes a plenty of details including:

  • The crash stack trace
  • All Network and console logs
  • An environment snapshot
  • Visual reproduction steps

For full disclosure, I work at Instabug. Let me know if I can help.

If you're using ADB just launch your app in debugging mode to gain a possibility to watch variables/expressions at runtime. You also can see the stacktrace in a Logcat window of your IDE if your app crashes.

there are several ways to do that, activate the LogCat and you will see there detailed info about what happens with your App.

or you will implement an error Handling sending the Exception info to a Toast

 try {
    ...
    your code
    ...
 } catch (IOException e) { 
     Toast.makeText(getApplicationContext(), "Exception Info " +     e.getCause(),Toast.LENGTH_LONG).show();
    e.printStackTrace();
 }      

updated

Use the Android's Log class, and logcat, for example:

Log.d( "Your app name", "The value of x is: " + x );

And in logging output you'll get something like:

D/Your app name( 1001): The value of x is: 96

You can get logging output from command line by running: "adb logcat", or using Dalvik debug monitor (ddms in the tools directory of Android SDK)

Using Log is superior to using Toasts since Toasts are gone quite quickly, and logcat will show you a lot of information upon application crash (like filename and line number which caused unhandled exception)

You can also catch the logs by DDMS tool by android. Just type DDMS in cmd and it will show ua GUI with running logs and more stuff for debugging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM