Android header preferences on small screen / phone

Short version: If your android preference headers are displaying on a small screen, but not opening the associated preference fragment when clicked, make sure you don’t have launchMode attribute set on your preferences activity in your AndroidManifest.xml file.

Long version: The concept of two-pane preferences of course applies to large screen (tablet) devices, where the left hand-side is a list of ‘headers’ and the right hand side is an associated preference fragment. Google’s built-in template for ‘SettingsActivity’ shows how this can be implemented such that when the activity is displayed on a small screen (e.g. phone) the preference headers are not displayed and instead all preferences are shown on the one screen, separated by categories. To do this they force you to use a deprecated API, which is pretty ugly. Additionally, this only makes sense when you don’t have many preferences. Once you have a large number of preferences, it may make sense to use headers on a small screen, which was the case for me, however it wasn’t working. The headers were displaying fine, but whenever I tapped one, nothing would happen, the onCreate() method of the associated fragment would not be called. By trial and error I finally found that I had

android:launchMode=”singleTask”

in my manifest file. As soon as I removed that attribute, preference headers worked on a small screen fine.

“No Permissions” when listing android devices

When plugging in a new Android device to your computer for debugging, you might see this when executing adb devices:

List of devices attached
???????????? no permissions
13716365315 device

This shows that 2 devices are attached, but only 1 of the two are working / recognised. To solve this you can try killing and restarting the adb server. To do this on linux, change to your android-sdk-linux/platform-tools directory in a terminal shell, then type:

sudo su
adb kill-server
adb start-server

Now try adb devices again and hopefully you see your device ok.