Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is need /advantage of services in android over multithreading

Tags:

android

Can you explain to me:

What is the need or advantages of services in Android over multithreading?

like image 792
Angel Avatar asked Apr 11 '11 10:04

Angel


2 Answers

Benefits of Services over multithreading:

  • When running low on memory and needing to kill existing processes, the priority of a process hosting the service will be the higher.
  • You don't need an Activity to run.
  • Services can be invoked through intents.
  • You can use Permissions.

Some pitfalls:

  • It runs on the ui thread.
  • Use stopSelf() after you have finished your work.
like image 121
Macarse Avatar answered Nov 19 '22 08:11

Macarse


If you want to execute a long operation and do not want to interrupt it, you should use services. By using multi-threading operating system can kill your application easily, but if you register for a service, then it will wait for finishing that operation.

To sum up, you should use a service for critical operations like uploading photo, and you can use multi-threading where interrupting the operation is not critical.

like image 22
Yekmer Simsek Avatar answered Nov 19 '22 09:11

Yekmer Simsek