开发者

what is need /advantage of services in android over multithreading

Can you explain to me:

What is the need or advantages of services开发者_JAVA技巧 in Android over multithreading?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜