In my Android app I have created onKeyEvent() to “back”, “volumeUp” and “volumeDown” keys.
if (keyname=="back" and event.phase == "up") then native.requestExit() end
if ( keyname == "volumeUp" and event.phase == "down" ) then local masterVolume = audio.getVolume( { channel=1 } ) --here after app suspend masterVolume is equal to -1 if ( masterVolume \< 1.0 ) then masterVolume = masterVolume + 0.1 if audio.setVolume( masterVolume, { channel=1 } ) then end end return true elseif ( keyname == "volumeDown" and event.phase == "down" ) then local masterVolume = audio.getVolume( { channel=1 } ) if ( masterVolume \> 0.0 ) then masterVolume = masterVolume - 0.1 if audio.setVolume( masterVolume, { channel=1 } ) then end end return true end
Everything works. But if I press “back” key app suspends (but still in memory). In this case, if I run app again audio.getVolume() returns -1