The sample app does not show notification from "background page is inactive" state because when the background page is woken up, the event handler for chrome.pushMessaging.onMessage is not set up.
When user launches the app by clicking on its icon, the chrome.app.runtime.onLaunched() event is fired. But when background page is activated because of some incoming event (like push messaging or alarm), the onLaunched is not fired - instead, only the 'initial script', the JS code outside of functions, is executed. The initial script of background page must register event listeners so after initial load Chrome knows which handler to call. The sample app only registers the onMessage handler in onLaunched, but not from initial script.
It is easy to 'fix' the sample app - just move the call of setupPush() from onLaunched() handler to the very end of background.js file:
background.js:
....
// When a Push Message arrives, show it as a text notification (toast)
function showPushMessage(payload, subChannel) {
var notification = window.webkitNotifications.createNotification(
'icon.png', 'Push Message',
"Push message for you! " +
payload +" [" + subChannel + "]");
notification.show();
}
setupPush(); // <-- this executes every time page loads, not only in onLaunched
This will cause setupPush() to be executed every time background page is activated, whether user launched the app or the app is started in background in response to incoming push message.