0

Possible Duplicate:
Example: Communication between Activity and Service using Messaging

I'm having a trouble with my service, I googled from yesterday to now and got nothing decent result.

Now I have a activity with some buttons ( Play/Pause, Next, Previous) and a service (contains a MediaPlayer and others). I want to control my service to do somethings when I press a button on Activity.

I got how to send data from activity to service but that causes my problem.

To connect to service, I used startService(intent) with intent included some data, and in service class, I overrode onStartCommand(...) and now my service received that data.

That's great, but now I can not control my service.

And then, I approached to another way - Bound Service.

I also got how to create a bound service class and connect to it to interact with. But now, because onstartCommand is only called by startService() so I don't know how to get data from activity without override this method.

My question is: How to let activity control and send data to a service? Thank you.

Community
  • 1
  • 1
Paul
  • 950
  • 2
  • 12
  • 28
  • Oh, I have changed some methods in service class to static and in activity class I call that method through Service class. Thats OK. But using static for all method like what I said above is good??? Is that make my app become slower because use more memory? – Paul Oct 23 '12 at 14:02
  • You should read http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging. – Gaurav Oct 23 '12 at 14:07
  • I've read it before but I'm looking for a solution about Bound service, ( not Message now). anyway, thank you for your help. – Paul Oct 23 '12 at 14:17
  • Should I change all methods in service class to static?, This help me do not create service connection and a LocalBinder as well. I just call method that I want from service by access throught static method. – Paul Oct 23 '12 at 14:44

0 Answers0