0

I am trying to understand the tutorial on the android developer web site: http://developer.android.com/reference/android/app/Service.html

I understand most of it expect where its uses this bit code in the "Remote Messenger Service Sample" section of the tutorial ...

private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className,
        IBinder service) {
    ...

    Toast.makeText(Binding.this, R.string.remote_service_connected,
            Toast.LENGTH_SHORT).show();
}

... where is Binding.this defined? Is that a typo? There are several other places in the tutorial where Binding.this is used but there is no explanation about what Binding is or how it gets initialized.

Binding.this gets used here like so ...

void doBindService() {
    // Establish a connection with the service.  We use an explicit
    // class name because there is no reason to be able to let other
    // applications replace our component.
    bindService(new Intent(Binding.this, 
        MessengerService.class), mConnection, Context.BIND_AUTO_CREATE);
    mIsBound = true;
    mCallbackText.setText("Binding.");
}

Any help is appreciated thanks!

Red Cricket
  • 9,762
  • 21
  • 81
  • 166

1 Answers1

1

It's just the outer containing class. In this case, you can see by its usage it derives from Context. By the naming, you can deduce that it's the class that's binding to the Service, most likely an Activity.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • Yes ... I needed to change `Binding` to `MainActivity` (the name of my Activity class). Thanks! – Red Cricket Feb 25 '13 at 06:49
  • BTW I found that this http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging is a FAR better tutorial than the one on developer.android.com. – Red Cricket Feb 25 '13 at 06:51