The Problem

What do you do when your app freezes up, becomes unresponsive, and the logcat just isn’t being helpful? I found myself in this exact situation while debugging a music player I’m currently developing. For context, this is the Now Playing screen of the app where the problem arose:

As you can see, we’ve got all the basics: title, artist, album and some nice images (artist image and album cover) to tie everything together. For most songs this screen loads just fine, but for some reason, playing a few seconds of Dum Dee Dum by Keys N Krates, turned the app into an unresponsive mess. Clicking or swiping on any part of the screen gave no response, and my entire device (Nexus 6P), not just the app, became incredibly sluggish, if not completely unresponsive. Eventually, the Now Playing screen would just terminate, returning to the previous Activity, while the logcat would reset itself as if the app had just launched. Something was very wrong.

Looking for clues

The logcat wasn’t giving me any useful information as to where the problem could be, just that there was a problem. There were several entries in the logcat along the lines of

I/Choreographer: Skipped 265 frames! The application may be doing too much work on its main thread.

as well as

W/art: Suspending all threads took: 170.488ms

but no actual stacktrace. How was I supposed to know what was going on with my code? In desperation, I turned to Android Studio’s performance monitors, which easily allow you to visualize the behavior and performance of your app. More information about Android Studio’s performance monitors can be found here, but there are basically 4 monitors you need to know about: the Memory, CPU, GPU, and Network monitors. I opened up the performance monitors, and reproduced the bug. The CPU, GPU, and Network monitors, were relatively stable and uninteresting. However, the Memory monitor had a story to tell…