//Activity生命週期
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
// 連線到Google API用戶端
if (!googleApiClient.isConnected() && currentMarker != null) {
googleApiClient.connect();
}
}
@Override
protected void onPause() {
super.onPause();
// 移除位置請求服務
if (googleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(
googleApiClient, (com.google.android.gms.location.LocationListener) this);
}
}
@Override
protected void onStop() {
super.onStop();
// 移除Google API用戶端連線
if (googleApiClient.isConnected()) {
googleApiClient.disconnect();
}
}