From what I understood, an Android service and is nothing more than a wrapper around, respectively manager for, a thread. One can't do any lengthy operations as it is running in the context of the application's main thread (which happens to manage UI calls as well).
By default service runs in main thread but you can run it in different thread as well. Also it has its own lifecycle and it can run in both started state as well as bound state.
Hence service is useful to do long running tasks if it runs in a background thread.
Service is not a wrapper around thread. It is having a proper lifecycle methods.
From my understanding, the benefits of an Android Service are that you can run a thread that is separate from the Application as a whole. This allows you to continue operations of the Service even if the Application is not running.
an Android service and is nothing more than a wrapper around, respectively manager for, a thread.
No. Services do not have a separate thread by default. Services can create threads (and usually do), and some specific Service subclass create threads by default (e.g., IntentService).
the Application class would basically cover the same functionality
The Application class does not cover the same functionality, any more than an AnonymousCoward class would. An Application instance does not create a thread, either. Any sort of thread manager (e.g., ThreadPoolExecutor) might be used by a service but does not replace a service.
Primarily, a service exists as a flag to the operating system, indicating that you are actively delivering value to the user, and therefore Android should aim to terminate other processes — not yours — when it gets low on system RAM. Secondarily, a service provides a couple of APIs for IPC: the “command” pattern (Intent and startService()) and the “binding” pattern (bindService()).
An Application always exists in an app (an instance is created when the process is started). It does not serve as any sort of flag to the OS to indicate process importance, nor does it have any sort of IPC capability.
Asked in February 2016Viewed 2,036 timesVoted 7Answered 3 times