What is the best practice – let each Activity maintain its own connection to Service, or create a static class that holds a single Service connection?
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.
You assume those are your only two options. Of those two, the former is the only one that is possible, using your literal terms.
Personally, I recommend you consider the command pattern wherever possible — use
startService()to send a command (in the form of anIntent) to the service, which does the work and callsstopSelf()when appropriate. This works well with anIntentService, as theIntentServicewill process the command on a background thread and automatically callsstopSelf()when there is no more work to be done.