5
Debugging Android Apps

In this chapter, you will find out what to do when apps get buggy. You will learn how to use Logcat, Android Lint, and the debugger that comes with Android Studio.

To practice debugging, the first step is to break something. In MainActivity.kt, comment out the code in onCreate(Bundle?) where you initialize binding.

Listing 5.1  Commenting out a crucial line (MainActivity.kt)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    Log.d(TAG, "onCreate(Bundle?) called")
    // binding = ActivityMainBinding.inflate(layoutInflater)
    ...
}

Run GeoQuiz and see what happens. The app will crash and burn almost immediately.

If you watch the screen, you may see the app appear for a brief moment before vanishing without a word. On older versions of Android, you might see a dialog pop up. If you do not, launch the app again by pressing the GeoQuiz icon on the launcher screen. This time, when the app crashes you will see a message like the one shown in Figure 5.1.

Figure 5.1  GeoQuiz is about to E.X.P.L.O.D.E.

GeoQuiz is about to E.X.P.L.O.D.E.

Of course, you know exactly what is wrong with your app. But if you did not, it might help to look at your app from a new perspective.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.131.255