I saw this sample on how to bind a service and call its methods from an Activity.
http://developer.android.com/reference/android/app/Service.html#LocalServiceSample
But I want to bind a service and call its methods from a non-Activity class.
how can I do this?
as i don't have implementation of the following methods:
bindService, unbindService
By the same way like from Activity
just take/pass instance of content
Activity
Lets say you have MyActivity
class
and OtherClass
class
so you run in OtherClass
public class OtherClass {
Context mContext;
public void init(Context context){
mContext = context;
}
...
mContext.startService(new Intent(mContext, SomeService.class));
[EDIT]
In your case:
Intent intent = new Intent(mContext, LocalService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
See documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With