Android Question Can two services share the same notification?

pjetson

Member
Licensed User
Longtime User
I have an app that has a main activity and two services – the activity runs the user interface, one service is just to always show the current state of the app in the notification area and allow the user to easily re-open the app, and the other service runs as a foreground process when data needs to be sent to a host. Depending on circumstances, this second service may sometimes take a long time to complete.

Is it possible for both services to "share" the same notification object, rather than have two notifications when the second service is running? If so, what would I need to do to implement this?

I guess that I could stop the first service while the second service is running, and then restart it afterwards, but that seems a bit messy.
 

DonManfred

Expert
Licensed User
Longtime User
Why you need a foreground service to send data to your server???
I´m using okhttpjobs all the time and i´m uploading a lot of data to my server.
I don´t need a Foregroundservice to do that.
No, i think you cannot share the Icon
 
Upvote 0

pjetson

Member
Licensed User
Longtime User
Why you need a foreground service to send data to your server?
Hi, Manfred. The data transfer part is a little complex, and a foreground service seemed to be the best way to handle it.

Uploading the data to the host usually happens immediately, and in that case, there would be no need for a service. However, if there is no network access at the time (in the app's use case, this is quite likely), the app queues the data and tries to send it again in 15 minutes via a StartServiceAt. The phone has probably gone to sleep in this time, or the user might be using another app, or might be making a phone call, or whatever. More data might accumulate in this time as well.

When there is a lot of data to send, the data transfer can take a while to complete, so a service seemed the best solution. I might have been able to use a sticky service, but a foreground service seemed a better match.

Peter
 
Upvote 0

Misterbates

Active Member
Licensed User
As to the notification, designate one component of your app to be the notifier, then have the other components supply updates to the notifier which in turn updates the notification.
 
Upvote 0
Top