Honestly, I have always used Service and did not know of the existence of WorkManager and I recently have been advised with the latter.
However I am having difficulties in understanding if I should "migrate" my code from Service to WorkManager.
I will present you with these two scenarios:
- I have a Service that run indefinitely in the foreground that basically override the clipboard listener. Every time a new clipboard event is triggered, perform some tasks. Each task vary just a little bit depending on the action selected (PendingIntent) from the notification bar. The service ends when the user decide to stop it or it's killed by the system.
- I have a Service that run indefinitely in the foreground that capture the screen (MediaProjection) and perform some analysis on the captured media (video or image). The service ends when the user decide to stop it or it's killed by the system.
From what I understand the main benefit of using WorkManager is that the work will always finish even after the system decide to kill the process. Is that true? Since the system might kill a service after hours of heavy tasks, one must need to manually restart the service or the service will restart itself when the system will allow it. This way there would be no need to restart it manually or to wait for a restart by the OS, right?