I simply want to call methods of a local service from my activity. How can i do that ?
A obj = new A();
obj.method();
Service is a Java class. So how would you call a service method?
serviceObj.method();
Service serviceObj = new Service();
Definitely not.
In Android, Service is a System component that is created, destroyed and managed by Android OS.
For creating a service object you need IBinder.
This is how you can get a Service object from IBinder.
Once you have a hold of serviceObject. It will work like any normal Java object.
The above thing explained in the figure is called Binding a Service.
Binding makes possible to observe a background service from an Activity. With binding, we can communicate in both ways ie Activity<--->Service.
Prateek Yadav has already provided an excellent code snippet. You can use that.
startService(intent) and bindService(mIntent, mConnection, BIND_AUTO_CREATE) in any order. Binding and Starting a service are two independent things.