What you need / advantages of services in android for multithreading

Can you explain to me:

What is the need or benefits of services in Android for multithreading?

+6
source share
2 answers

If you want to perform a long operation and do not want to interrupt it, you must use services. Using a multi-threaded operating system, you can easily kill the application, but if you register for the service, it will wait for the completion of this operation.

To summarize, you should use the service for critical operations such as uploading a photo, and you can use multithreading where interrupting an operation is not critical.

+5
source

Benefits of Services for Multithreading:

  • When working at low memory levels and, if necessary, killing existing processes, the priority of the process on which the service is located will be higher.
  • You do not need to run Activity .
  • Services can be called via intents .
  • You can use Permissions.

Some pitfalls:

  • It works in ui thread.
  • When finished, use stopSelf() .
+5
source

Source: https://habr.com/ru/post/885641/


All Articles