3

I am creating an Android app (Java code) that has an audio call feature. I managed to make it work using the webRTC framework. I wanted to make my audio call behave like WhatsApp and Messenger, where those apps keep the audio call running even if the user stops the app from apps history, or starts using another app.

So, I decided to migrate the webRTC code from an Activity to a Foreground Service. My Audio Call Activity handles the UI, displaying friend photo, name, call timer ... So I had to make communication between my Activity and my Foreground Service through binding and sending android.os.Message object.

Everything works fine when using SAMSUNG devices, if I kill the app, I could return to the Call activity by clicking the foreground service's notification, and the audio call keeps working until I hang up.

My problem appeared when i used a Xiaomi device (redmi note7), if i kill the app, the audio call stops, cause my Foreground Service is restarted. Even after enabling "Autostart" from settings.

I searched in here for a solution but all the answers i found didn't satisfy my need, cause i can't just accept my Service being restarted. If i want to resume the audio call, i have to re-call the friend again !

So, the question is : How to prevent Xiaomi, Huawei, Oppo ... devices from restarting Foreground Service ?

Which is the case with WhatsAPP, Messenger, Instagram and others.

OussaMah
  • 817
  • 9
  • 19
  • 1
    Checkout this [link](https://dontkillmyapp.com/). It explains what to do in order to keep your service alive on every vendor. – Tomer Petel Oct 29 '19 at 12:14
  • Thank you for your answer. Then link you shared provides great information, better to be known by developers. Unfortunately, i couldn't find a solution for my problem. I started thinking to give up for now. Those vendors are whitelisting WhatsApp, Messenger, Viber and other famous apps. But for our apps it is impossible. – OussaMah Oct 29 '19 at 12:48
  • Good to know. Posting as an answer. – Tomer Petel Oct 29 '19 at 12:50

1 Answers1

1

It's a tricky question since it really depends on the vendor. There is a site which document and rank the vendor according to "how bad" they're handling services and processes. From the site:

...With Android 6 (Marshmallow), Google has introduced Doze mode to the base Android, in an attempt to unify battery saving across the various Android phones. Unfortunately, vendors (e.g. Xiaomi, Huawei, OnePlus or even Samsung..) did not seem to catch that ball and they all have their own battery savers, usually very poorly written, saving battery only superficially with side effects.

The solutions differs from vendor to vendor and from ROM version to another. For example for Huawei you can overcome the issue in Huawei P20, Huawei P20 Lite, Huawei Mate 10 by Phone settings > Battery > App launch and then set your app to “Manage manually” and make sure everything is turned on. Also for reliable background processes you may need to uninstall PowerGenie (which is a power mgmt. application by Huawei). On the other hand for EMUI 9+ devices you'll have to uninstall PowerGenie via adb

Tomer Petel
  • 334
  • 3
  • 11