Why does Android silently kill my app when minimized?

Jean-Francois Cartier
Samsao
Published in
3 min readAug 29, 2014

I recently had a weird bug with an Android application we are developing. When minimized (or paused, or put in background), the application would crash. Actually, it wouldn’t crash, it would just stop.

As you can see, there is no crash dialog, but the app was not running anymore. There was also nothing in the console when debugging…

So where do we go from there? As for every bug, I tried asking Google first. However, as it rarely happens, I couldn’t find anything about this bug. Litteraly, I couldn’t find anything (I mean, on the first page) about it. So I had to stop being lazy and investigate this bug.

I had to pinpoint the problem. I realized it was not happening on my device, but only on the emulator. So I thought this could be related to the emulator. However, after trying the application on my colleagues’ phones, it turned out my asumption was false. I have a Nexus 5 running Android L preview and my collagues use a Nexus 5 with 4.4.2 and a Nexus 4 with the same Android version. The app would crash on both their phone. Ok… so what?

Since I couldn’t stop being completely lazy, I asked my colleague if he had any idea what it could be. We managed to find that it did not happen in every activities of the application. Since every Activity in the application extends from the same one, it was due to another form of activity customization. The Android manifest…

After a little bit of digging, we found out that the bug was related to the android:label attribute of an <activity> tag. Since the application uses a custom font in the Action Bar, I had put an empty label for the launching activity, like so:

<activity android:label="" 
...

I did this because if the activity had a label, this label would appear with Android’s default font during the application launch, before switching to the custom font. By putting an empty label, only the custom font would appear, which looked better, but unknowingly created a really bad (and hard to debug) side effect. As you can see on the first image, a minimized application has a label, which is the running activity’s label. Since Android does not know what to do with an empty minimized application label, it seems it silently kills the application.

As mentioned earlier, the application worked fine on my phone running Android L preview. So it seems like this “bug” is fixed in that version on Android. However, if you encounter this weird behaviour with older versions, I hope this post will save you the headaches I had to endure :)

--

--