簡體   English   中英

developer.android.com服務教程不明確

[英]developer.android.com Service tutorial not clear

我正在嘗試了解android開發人員網站上的教程: http : //developer.android.com/reference/android/app/Service.html

我了解大多數人希望它在本教程的“遠程Messenger Service示例”部分中使用此位代碼。

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

任何幫助表示贊賞,謝謝!

它只是外部的包含類。 在這種情況下,您可以通過它的使用看到它是從Context派生的。 通過命名,您可以推斷出綁定到Service的是類,很可能是Activity

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM