Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Service Limitations Android and voip app

I am working on the voip app. I do all the logic regarding the signaling on background service. When user exists the app I am stoping the service. In this case, I am not connected to the server. When I am in this state, server is sending the push notification (FCM), I am starting the service and creating notification for incoming call or message. This is all good so far:)

I have read about the limitations for Oreo for backgrounding services and realize that now I need to start service in foreground while showing notification. Then I wanted to check how the Hangouts(google) does it, and of course they are running the service in the background when message is received. Am I missing something?

Thank you

like image 564
User1980 Avatar asked Dec 07 '17 13:12

User1980


1 Answers

Visible activity = foreground

When user exists the app I am stoping the service

If this means that the service is running only when your app is visible to the user, then the process and the service is actually in the foreground and you shouldn't experience any problems with system killing your service:

An app is considered to be in the foreground if any of the following is true:

  • It has a visible activity, whether the activity is started or paused.

FCM received = foreground

Also, receiving high-priority FCM messages will put your app on temporary whitelist for background processing, and you will have more than enough time to do your processing at that time, or you can always start a foreground service after FCM is received - like a service that handles the call and should display a notification while running:

Under certain circumstances, a background app is placed on a temporary whitelist for several minutes. While an app is on the whitelist, it can launch services without limitation, and its background services are permitted to run. An app is placed on the whitelist when it handles a task that's visible to the user, such as:

  • Handling a high-priority Firebase Cloud Messaging (FCM) message.

Your app design - handling incoming calls by receiving priority FCM and then creating a foreground call service - seems reasonable.

Refer to the documentation which is really clear on these subjects.

like image 53
maciekjanusz Avatar answered Nov 10 '22 00:11

maciekjanusz