Question

We're writing a chat app and have got the Pubnub service running in the background, listening for messages and firing a Notification Intent on receipt. The problem is that we're using a partial wake lock when the phone is sleeping and that just kills the battery (app takes up >20% of battery).

Is there a less CPU intensive way of listening for messages? I've also tried looking around for code examples of Pubnub push notifications on Android, but haven't found any.

Thanks, Saswat

Was it helpful?

Solution 2

According to this website:

COMING SOON: GCM push notifications are in beta and will be release around the beginning of June.

But, that website's date states:

PubNub Support posted this on July 19, 2012 19:59

So to answer your question: At the moment, there is no less-CPU intensive way of listening for messages than using a wake-lock. in fact, PubNub specifically states that you should use a partial wake lock on that website linked above.

There is also no documentation on the Android PubNub github. They state there that PubNub is better than Google C2DM. Google C2DM was deprecated years ago now.

OTHER TIPS

PubNub’s Android SDK background process has been optimized through many iterations. Our benchmarks show virtually no difference in battery drain between a partial wake lock doing nothing, and a PWL+PubNub socket.

Even measuring the most power-intensive use case, which is a 4G connection, we’ve benchmarked over a 4 hour period on a Nexus 4, the difference between no wait lock, and PWL+PubNub was 4% battery difference over 4 hours, with the device receiving a 1k message every 5 minutes. On Wi-Fi, the difference is much less.

While GCM has many minutes of socket timeouts (per this thread,) PubNub is always reliable. However, you can configure PubNub disable PWL for applications where real-time isn't always required, but reliability is. In our opinion, this customizability makes PubNub the most developer-friendly option for power-efficient socket communication.

If you're still seeing noticeable battery drain, please contact support@pubnub.com with a copy of the relevant code so we can help debug and advise on best practices.

Cheers!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top