Debugging and logging in Android Studio
Debugging and logging are crucial in Android development, and you can write log messages that appear in Logcat to help you find issues in your code or verify a piece of code executes when it should.
We will introduce this topic here, but it is unfair to say we will cover it all in just one recipe; for that reason, we will cover more about debugging and logging in Chapter 12, Android Studio Tips and Tricks to Help You during Development.
Getting ready
Let us use an example to understand logging. The following log methods are listed from the highest to lowest priority. They are proper when logging network errors, success calls, and other errors:
Log.e()
: A log errorLog.w()
: A log warningLog.i()
: Log informationLog.d()
: Debugging shows critical messages to developers, the most used logLog.v()
: Verbose
A good practice is associating every log with a TAG
to identify the error message in Logcat quickly. A...