I have a Worklight hybrid app with basic push notification working in android. If the app is running and in focus when the notification is pushed, it behaves exactly as I would expect. The notification callback in my app is called, and it pops up a SimpleDialog. All Good.
If I dismiss the app by clicking on the Home Button, and a new message arrives, I see the notification in the Android notification area, and when I click on the item in the android notification list, the item gets dismissed from the list (but the app does not come back into focus) If I then launch my app from the Apps menu, it is sitting where I left it and the SimpleDialog is showing. (my notification handler was called) Mostly good, but I expected the app to come into focus when I selected the notification in the android notification list.
If I dismiss the app by clicking on the Back Button, and a new message arrives, I see the notification in the Android notification area, and when I click on the item in the android notification list, the item gets dismissed from the list (but the app does not come back into focus) If I then launch my app from the Apps menu, it launches the app fresh (I have to log in again) and my notification handler is never called. Not so good.
If I force stop the app, or turn the phone off while the notification is being sent (but leave the subscription in place), the notification never shows up on the phone. I don't see it in the Android Notification area when I restart the phone, and the notification handler in my app is never called when I launch the app. Very bad.
Is this the expected behavior?
I'm using Worklight 5.0.6.1, and I've seen this behavior on Android emulator at platform 4.2.2 and a physical phone at platform 4.1.2
EDT: Adding the code.
The adapter:
WL.Server.createEventSource({
name : "MyPushEventSource",
securityTest: "MyApp-strong-mobile-securityTest"
});
function submitNotification(userId) {
var userSubscription = WL.Server.getUserNotificationSubscription(
'MyPushNotification.MyPushEventSource', userId);
if (userSubscription == null) {
return {
result : "No subscription found for user :: " + userId
};
}
var notification = WL.Server
.createDefaultNotification("There's work to be done!", 1, {});
WL.Server.notifyAllDevices(userSubscription, notification);
return {
result : "Notification sent to user :: " + userId
};
}
and in the app:
WL.Client.Push.onReadyToSubscribe = function() {
var pushSubscribe_Success_Callback = function(response) {
WL.Logger.debug("Enter: pushSubscribe_Success_Callback");
};
var pushSubscribe_Fail_Callback = function(response) {
WL.Logger.debug("Enter: pushSubscribe_Fail_Callback");
};
var pushNotificationReceived = function(props, payload) {
WL.SimpleDialog.show("Notification", props.alert, [
{ text : "OK" }]);
};
WL.Client.Push.registerEventSourceCallback("myPush",
"MyPushNotification", "MyPushEventSource",
pushNotificationReceived);
if (!WL.Client.Push.isSubscribed("myPush")) {
WL.Client.Push.subscribe("myPush", {
onSuccess : pushSubscribe_Success_Callback,
onFailure : pushSubscribe_Fail_Callback
});
}
};
As I said, if the app is in focus, this all works without a hitch, so I know I have the Google messaging account and keys set up correctly. But for some reason I'm seeing unexpected results if the app isn't in focus when the notification is published.
See Question&Answers more detail:
os