@Override public void run() { if (serviceConnection == null) { return; } AppService appService = serviceConnection.getService(); if (appService == null) { Toast.makeText( TrackpointsListActivity.this, R.string.gps_service_not_connected, Toast.LENGTH_SHORT) .show(); return; } if (!appService.isListening()) { // location updates stopped at this time, so let's start them appService.startLocationUpdates(); } else { // gpsInUse = false means we are in process of stopping // listening appService.setGpsInUse(true); // if both isListening and isGpsInUse are true - do nothing // most likely we are in the process of recording track } // this activity requires compass data appService.startSensorUpdates(); // let's not wait for LocationListener to receive updates and get last known location currentLocation = appService.getCurrentLocation(); waypointsArrayAdapter.notifyDataSetChanged(); }
@Override public void onPause() { unregisterReceiver(compassBroadcastReceiver); unregisterReceiver(locationBroadcastReceiver); AppService appService = serviceConnection.getService(); if (appService != null) { // stop location updates when not recording track if (!appService.getTrackRecorder().isRecording()) { appService.stopLocationUpdates(); } // stop compass updates in any case appService.stopSensorUpdates(); } serviceConnection.unbindAppService(); super.onPause(); }