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 throughintents
.- 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.
精彩评论