In what cases should I start Service and in what case bind Service? For example – an android client for Music Service? Are the any differences in the priority for the System;are the any common rules; anything else?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
startService()for services which will run independently after you start them. Music players are a good example. These run until they callstopSelf()or someone callsstopService().You can communicate with a running service by sending Intents back and forth, but for the most part, you just start the service and let it run on its own.
Use
bind()when the service and client will be communicating back and forth over a persistent connection. A good example is a navigation service which will be transmitting location updates back to the client. Binders are a lot harder to write than intents, but they’re really the way to go for this usage case.Regarding the priority: When all activities of a process lose their visibility, the process becomes a service process if it hosts a service which was started with
onStart(), otherwise it becomes a background process. Service processes have a higher priority than background processes. Further details at the android developer site.If a service process without visible activity needs a higher priority (e.g. a music player which really should not be interrupted), the service can call
startForeground().