BY DEFAULT, WHEN A SERVICE DECLARED IN THE ANDROIDMANIFEST, IN WHICH THREAD WILL IT RUN?

Asked 8 years ago 828 views

1

BY DEFAULT, WHEN A SERVICE DECLARED IN THE ANDROIDMANIFEST, IN WHICH THREAD WILL IT RUN?

1 Answer


0

By Default, a service runs on the main thread. So if you want to do some long running task you need to make your service run on the background thread.

There are basically three types of service - 

  1. Bound
  2. Foreground
  3. Background

To create a service you need to create a subclass for service or use any existing subclass for the service. It is important to override some of the important callback methods of service class in order to run a service properly.  There are some callback methods which need to be implemented such as-

  1. onStartCommand
  2. onBind
  3. onCreate
  4. onDestroy

In manifest, you need to declare your service - 

<manifest ... >

  ...

  <application ... >

      <service android:name=".ExampleService" />

      ...

  </application>

</manifest>

Write Your Answer