0

Greetings I am creating a service client and the following lines give me error. I was wondering how to fix these...

//  I have put in the service client stuff below...

private  CheckZone mBoundService;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName CheckZone, IBinder service) {
    // This is called when the connection with the service has been
    // established, giving us the service object we can use to
    // interact with the service.  Because we have bound to a explicit
    // service that we know is running in our own process, we can
    // cast its IBinder to a concrete class and directly access it.
    mBoundService = ((CheckZone.LocalBinder)service).getService();

    //This line complians about binding, and states that it can not be resolved.  How do I fix this please?
    Toast.makeText(binding.this, "Connected to CheckZone", Toast.LENGTH_SHORT).show();
}
forsvarir
  • 10,749
  • 6
  • 46
  • 77
Sean
  • 47
  • 14

3 Answers3

1

I just ran into this issue using the same sample Local Service Sample code from http://developer.android.com/reference/android/app/Service.html, Toast.makeText wasn't happy with just this. You need to use classname.this

e.g.

public class MyClass extends Activity {
  private ServiceConnection mConnection = new ServiceConnection() {

    public void myMethod () {
                Toast.makeText(MyClass.this,
                R.string.local_service_connected,
                Toast.LENGTH_SHORT).show();
    }
  }
}

Without MyClass. you get the error:

The method makeText(Context, int, int) in the type Toast is not applicable for the arguments (new ServiceConnection(){}, int, int)

The reason is that you're actually in an inner class.

See: Using "this" with class name

And, of course, the classname left off of the sample code is Binder so if your class was called that, it would just work.

Community
  • 1
  • 1
Campey
  • 390
  • 2
  • 10
0

I think you are referring to a compilation error? Binding is not defined? Just get rid of binding.this and just use, "this"

Greg Giacovelli
  • 10,164
  • 2
  • 47
  • 64
0

Do you have a LocalBinder in your CheckZone service?

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103