LocationClient.getLastLocation()
来获取上次已知的位置。这似乎很简单。理想情况下,我只需在每个活动中创建一个LocationClient并调用getLastLocation()。但是,还需要进行一些额外的工作来连接到Google Play服务,例如调用
LocationClient.connect()
并处理onConnected
、onDisconnected
和onConnectionFailed
回调。文档在此处:https://developer.android.com/training/location/retrieve-current.html
据我所知,我五个不同的活动都必须处理LocationClient的生命周期方法。它们也不能立即在onCreate()
中调用getLastLocation()
,因为该活动的连接可能尚未建立。是否有一种简单的方法来简化LocationClient的生命周期,以便在我为应用程序建立连接后,任何新活动中都可以立即使用
getLastLocation()
?