Reputation: 77596
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?
Upvotes: 3
Views: 926
Reputation: 1085
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:
For full disclosure, I work at Instabug. Let me know if I can help.
Upvotes: 5
Reputation: 126455
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
Upvotes: 4
Reputation: 113
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.
Upvotes: 0
Reputation: 2764
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)
Upvotes: 0
Reputation: 19378
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.
Upvotes: 4