System Notification not running in background
I have developed a Web application using Phonegap which reads cross domain Rss feeds using Google-Feed API and sends system notification to the user if a new feed is available.
I have used this Phonegap System Notification Pl开发者_开发技巧ugin for creating push notifications.
This is the SystemNotificaton.java that comes with the plugin.
This is the SystemNotification.js file that comes with the plugin, which has all the methods that can be used in your javascript file.
This is my notification.js javascript file were I have created two functions to read two separate Rss feed urls and I have used setIntervals to call the function every 1 min.I have also called navigator.systemNotification.onBackground(); method inside the same function so that when my app is not active this function keeps running in the background and displays the notification to the user if a new feed comes up.
The problem is I get notifications once the application starts then when i close the application I get a couple of more, after one or two days the notification stops coming. I know since I am using google-feed api it is not real time but still even after two days it does not work . It seems like the onbackground method it not working. Could anyone point out what mistake I am doing.
I don't know much about Phonegap, but I know a fair bit about Android development, and it sounds to me like the notifications aren't your problem. (Incidentally, these are just notifications, not "Push" notifications. Those are another beast altogether.)
I suspect that your application is simply stopping, and you don't have anything set to start it back up. The Android OS will kill any background application for a variety of reasons. If implemented as a service, the OS is supposed to restart it at some point, but that's not entirely reliable.
Basically, you need to set an alarm to babysit your service and make sure it stays alive. If this is possible in PhoneGap, I recommend getting rid of the setInterval altogether, and just using the alarm to wake your app up and trigger the RSS polling action. The benefit of this is that it will still work when the device goes to sleep.
Doing a bit of quick searching seems to indicate that PhoneGap does not have access to the AlarmManager. It could be done with a plugin, maybe, but PhoneGap doesn't strike me as a good framework for background services in general. A truly native app is going to be far better behaved in this context.
精彩评论