2013-02-25 57 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