2013-02-25 54 views
0

我想了解在Android开发者网站上的教程:http://developer.android.com/reference/android/app/Service.htmldeveloper.android.com服务教程不清楚

我了解大部分预计在那里它的用途在“远程Messenger服务示例此位码“部分教程...

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(); 
} 

...其中是Binding.this定义?这是一个错字吗?本教程中还有其他几个地方使用了Binding.this,但没有说明Binding是什么或者它是如何初始化的。

Binding.this被这里使用这样的...

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."); 
} 

任何帮助表示赞赏感谢!

回答

1

它只是外部包含的类。在这种情况下,您可以看到它的使用来自Context。通过命名,您可以推断出它是与Service绑定的类,最有可能是Activity

+0

是的......我需要将'Binding'更改为'MainActivity'(我的Activity类的名称)。谢谢! – 2013-02-25 06:49:24

+0

顺便说一句我发现这个http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging是一个比在developer.android.com上更好的教程。 – 2013-02-25 06:51:21