Take the 2-minute tour ×

I have created a service, called LocalService, and I want to bind to it so that it can perform some action and give the result back to the calling client. I've been trying to get the example of the android dev site to work but eclipse gives a compile time error on this method:

void doBindService() {
    // Establish a connection with the service. We use an explicit
    // class name because we want a specific service implementation that
    // we know will be running in our own process (and thus won't be
    // supporting component replacement by other applications).
    bindService(new Intent(Binding.this, LocalService.class), mConnection, Context.BIND_AUTO_CREATE);
    mIsBound = true;

There is a red line under "Binding.this" and eclipse gives me: Binding cannot be resolved to a type. What can I do?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Just remove Binding, code should look like this:

bindService(new Intent(this, LocalService.class), mConnection, Context.BIND_AUTO_CREATE);

First parameter of Intent constructor is Context. Code above will work if you calling it from your Activity class (any instance of Activity is a Context also). If not, you can always use application context

share|improve this answer

It looks like Binding is simply class name you put doBindService() in (most likely Activity?). If your class is named otherwise either rename it to Binding or replace all Binding.this with MyClass.this or just this.

share|improve this answer

Your Answer


