2014-04-30 51 views
4

在我的活動我採取瞭如下班Gplus用戶身份驗證和獲取用戶位置

com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks, 
com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener, 
com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks, 
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener 

這兩個接口是通過谷歌加認證用戶。

com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks, 
com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener 

而這些是獲取用戶當前位置

com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks, 
com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener 

的方法在這些類相同。

@Override 
public void onConnected(Bundle connectionHint) {} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) {} 

由於這些方法具有相同的參數和相同的返回類型我不能有兩個在同一類中。所以我想我需要確定從BundleConnectionResult調用哪個接口。我怎麼能做到這一點?我的意思是我需要檢查哪個關鍵值?如果需要澄清,請評論。 謝謝

+1

何去何從答案 http://stackoverflow.com/questions/2598009/method-name-collision-in-interface-implementation-java – Kamalone

回答

2

作爲 匿名 成員聲明實現接口如何?

public class Ac { 

    private GooglePlayServicesClient.OnConnectionFailedListener psConnectionFailedListener = 
      new GooglePlayServicesClient.OnConnectionFailedListener() { 

       @Override 
       public void onConnectionFailed(ConnectionResult connectionResult) { 
        // implementation 
       } 
      }; 

    private GooglePlayServicesClient.ConnectionCallbacks psConnectionCallbacks = 
      new GooglePlayServicesClient.ConnectionCallbacks() { 

       @Override 
       public void onConnected(Bundle bundle) { 
        // implementation 
       } 

       @Override 
       public void onDisconnected() { 
        // implementation 
       } 
      }; 

    private GoogleApiClient.ConnectionCallbacks googleConnectionCallbacks = 
      new GoogleApiClient.ConnectionCallbacks() { 

       @Override 
       public void onConnected(Bundle bundle) { 
        // implementation 
       } 

       @Override 
       public void onConnectionSuspended(int i) { 
        // implementation 
       } 
      }; 

    private GoogleApiClient.OnConnectionFailedListener googleConnectionFailedListener = 
      new GoogleApiClient.OnConnectionFailedListener() { 

       @Override 
       public void onConnectionFailed(ConnectionResult connectionResult) { 
        // implementation 
       } 
      }; 
} 
+0

同意你的看法是這樣的解決方案,但是這不*匿名聲明*,那將是*成員聲明*。 –

+0

已更新,謝謝 – JafarKhQ