开发者

Android Debugging?

What is the best way to debug an android application? Every once in开发者_JAVA技巧 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.


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


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.


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 u a GUI with running logs and more stuff for debugging.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜