Reputation: 1021
I was trying to create a service that can interact with the AppUI when the App is opened and continues its working when the App is closed.
I have heard that the bindService()
call creates a Bound Service that can communicate with the App. At the same time, Some resources say that the startService()
can be further made a Foreground Service by calling startForeground()
inside the onStartCommand()
callback, and then use them to communicate with the App.
Can anyone give the best way to achieve my need and the difference between this?
Upvotes: 2
Views: 3951
Reputation: 41
From the Official Documentation: https://developer.android.com/guide/components/services.html
Bound
A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, receive results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.
Foreground
A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a status bar icon. Foreground services continue running even when the user isn't interacting with the app.
It looks like you should use Foreground Service.
Upvotes: 3