嗨,是否有可能创建一个融合的位置提供者单例,它可以用来从许多活动中获得最后的位置?
此外,我将如何在这些活动中维护Google客户端实例的连接和断开。
发布于 2015-06-18 17:48:41
这是可能的。您将希望实现私有构造函数/ 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约定,但是像这样构造代码应该有效。
https://stackoverflow.com/questions/30355914
复制相似问题