Introducing Service
A Service
in Android, as referred to before, is an entity that runs without a user interface that could be used to execute any kind of business logic which the application requires during the execution.
If the basic unit of a visible application is Activity
, its equivalent unit for non-visible components is Service
. Just like activities, services must be declared in the AndroidManifest file so that the system is aware of them and can manage them for us:
<service android:name=".MyService"/>
Service has lifecycle callback methods, similar to those of Activity, that are always invoked on the application's main thread. Here are the most important callbacks that the user must define when it creates a service by extending the Service base class:
void onCreate(); void onDestroy() void onStartCommand(Intent intent, int flags, int startId) IBinder onBind(Intent intent) boolean onUnbind(Intent intent)
The onCreate()
is the lifecycle callback that is called once when the service...