0

Goal
Create a long-running background service with a network connection, similar to Zello app.

Problem
Starting with API level 26 (Oreo), there're tight restrictions on background services and their network activity.

Looking at the Zello app which has a constantly running background service which is able to accept audio and text messages even if the device is sleeping, I wonder how they achieved that? Their service is not running on the foreground. Also, it doesn't look like they use push messages for that, since the app works quite stable in conditions where there's a problem with push messages reception (e.g. low-end Xiaomi phones).

Any ideas would be appreciated.

davee44
  • 330
  • 3
  • 10
  • Some useful info on this site https://dontkillmyapp.com/ – Manohar Reddy Jan 10 '20 at 12:05
  • I'm pretty sure they do use push messages. Otherwise they'd have to constantly poll the backend for new messages which would very quickly drain the battery and also cause a lot of unnecessary data-usage on the device. – Ridcully Jan 10 '20 at 12:18

2 Answers2

1

From what I gathered these apps use the Firebase Cloud messaging service: https://firebase.google.com/docs/cloud-messaging/

The Firebase Service is embedded in the Android system and maintains a constant network connection to the firebase server. The apps then contact the firebase server which in turn to notifies the destination device.

Advantages:

  • The Android system is responsible of keeping the server connection alive and running
  • The network load is minimized because one connection is used for all apps using the firebase service.

Disadvantages:

  • All data is sent through the firebase server and is therefore (in theory) directly accessible by Google
  • Depedning on how many devices use your app, you need to pay for the service.

A similar question asked might be helpful in tackling the problem too: How does push notification technology work on Android?

Mindur
  • 206
  • 1
  • 4
0

These apps don't have long-running services with constant network connections. They use push notifications. When there is a new message for a user, the server sends a push notification to wake the device up.

David Wasser
  • 85,616
  • 15
  • 182
  • 239
  • yes, I thought so. but there are cases when other apps have a problem with push reception, while Zello keeps working stable. I tested it thoroughly. – davee44 Jan 14 '20 at 15:28
  • There are ways to make your app more robust. You can schedule wakeup jobs with the `JobScheduler`, you can have another app act as a "watchdog" on your app, etc. I don't exactly know how Zello works, but you could just contact the developers there and ask them if you really want to know. – David Wasser Jan 14 '20 at 16:41