2015-05-20 23 views
0

嗨,是否有可能創建一個融合的位置提供者單身人士,可用於從許多活動中獲取最後的位置?融合的位置提供者單例示例?

此外,如何在連接和斷開連接方面跨這些活動維護Google Api客戶端實例。

回答

0

這是可能的。您將要實現私有構造函數/的getInstance()組合 -

/** 
* Private constructor. 
*/ 
private GPSPlotter(Context theContext) { 
    initializeInstance(); 
    initializeFields(theContext); 
    buildApiClient(); 
    connectClient(); 
} 

/** 
* Returns an instance of the GPS Plotter. 
*/ 
public static GPSPlotter getInstance(Context theContext) { 

    if (gpsPlotterInstance == null) 
     return new GPSPlotter(theContext); 
    else 
     return gpsPlotterInstance; 

} 

我相當肯定的傳球語境爲模型參數對象與Android約定休息,但構建你的代碼像這應該工作。