The KeyListener won’t run when the application is paused (which it is if the screen is locked).
But there is a quite clever workaround: play some music (probably silence) and listen to volume changes.
See here for more information on how to do it. AFAIK the above behavior hasn’t changed and you mostly likely will have to resort to above workaround.
I’d love to be corrected on that as I’ve needed this myself.
2
solved Listening to volume button events while phone is locked