bind and unbind recording service in onStart and onStop

This commit is contained in:
Jimmy Shih
2012-10-31 11:21:21 -07:00
parent bf5b060123
commit 620b6e09b5
7 changed files with 67 additions and 57 deletions
@@ -51,15 +51,6 @@ public abstract class AbstractMyTracksActivity extends FragmentActivity {
*/ */
protected abstract int getLayoutResId(); protected abstract int getLayoutResId();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() != android.R.id.home) {
return super.onOptionsItemSelected(item);
}
onHomeSelected();
return true;
}
/** /**
* Returns true to hide the title. Be default, do not hide the title. * Returns true to hide the title. Be default, do not hide the title.
*/ */
@@ -73,4 +64,13 @@ public abstract class AbstractMyTracksActivity extends FragmentActivity {
protected void onHomeSelected() { protected void onHomeSelected() {
finish(); finish();
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() != android.R.id.home) {
return super.onOptionsItemSelected(item);
}
onHomeSelected();
return true;
}
} }
@@ -90,6 +90,18 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
updateUiByMarkerId(); updateUiByMarkerId();
} }
@Override
protected void onStart() {
super.onStart();
TrackRecordingServiceConnectionUtils.startConnection(this, trackRecordingServiceConnection);
}
@Override
protected void onStop() {
super.onStop();
trackRecordingServiceConnection.unbind();
}
@Override @Override
protected int getLayoutResId() { protected int getLayoutResId() {
return R.layout.marker_edit; return R.layout.marker_edit;
@@ -147,18 +159,6 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
} }
} }
@Override
protected void onResume() {
super.onResume();
TrackRecordingServiceConnectionUtils.resumeConnection(this, trackRecordingServiceConnection);
}
@Override
protected void onDestroy() {
super.onDestroy();
trackRecordingServiceConnection.unbind();
}
/** /**
* Adds a marker. * Adds a marker.
*/ */
@@ -202,23 +202,33 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele
} }
@Override @Override
protected int getLayoutResId() { protected void onStart() {
return R.layout.search_list; super.onStart();
TrackRecordingServiceConnectionUtils.startConnection(this, trackRecordingServiceConnection);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
TrackRecordingServiceConnectionUtils.resumeConnection(this, trackRecordingServiceConnection);
metricUnits = PreferencesUtils.getBoolean( metricUnits = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT); this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
} }
@Override
protected void onStop() {
super.onStop();
trackRecordingServiceConnection.unbind();
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
myTracksLocationManager.close(); myTracksLocationManager.close();
trackRecordingServiceConnection.unbind(); }
@Override
protected int getLayoutResId() {
return R.layout.search_list;
} }
@Override @Override
@@ -96,14 +96,14 @@ public class SensorStateActivity extends AbstractMyTracksActivity {
} }
@Override @Override
protected int getLayoutResId() { protected void onStart() {
return R.layout.sensor_state; super.onStart();
TrackRecordingServiceConnectionUtils.startConnection(this, trackRecordingServiceConnection);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
TrackRecordingServiceConnectionUtils.resumeConnection(this, trackRecordingServiceConnection);
isVisible = true; isVisible = true;
timer = new Timer(); timer = new Timer();
timer.schedule(new UpdateTimerTask(), 0, REFRESH_PERIOD_MS); timer.schedule(new UpdateTimerTask(), 0, REFRESH_PERIOD_MS);
@@ -120,11 +120,16 @@ public class SensorStateActivity extends AbstractMyTracksActivity {
} }
@Override @Override
protected void onDestroy() { protected void onStop() {
super.onDestroy(); super.onStop();
trackRecordingServiceConnection.unbind(); trackRecordingServiceConnection.unbind();
} }
@Override
protected int getLayoutResId() {
return R.layout.sensor_state;
}
/** /**
* Stops the temp sensor manager. * Stops the temp sensor manager.
*/ */
@@ -204,23 +204,21 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
showMarker(); showMarker();
} }
@Override
protected int getLayoutResId() {
return R.layout.track_detail;
}
@Override
protected boolean hideTitle() {
return true;
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
TrackRecordingServiceConnectionUtils.startConnection(this, trackRecordingServiceConnection);
trackDataHub.start(); trackDataHub.start();
AnalyticsUtils.sendPageViews(this, "/page/track_detail"); AnalyticsUtils.sendPageViews(this, "/page/track_detail");
} }
@Override
protected void onResume() {
super.onResume();
trackDataHub.loadTrack(trackId);
trackController.update(trackId == recordingTrackId, recordingTrackPaused);
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
@@ -228,11 +226,11 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
} }
@Override @Override
protected void onResume() { protected void onStop() {
super.onResume(); super.onStop();
trackDataHub.loadTrack(trackId); trackRecordingServiceConnection.unbind();
TrackRecordingServiceConnectionUtils.resumeConnection(this, trackRecordingServiceConnection); trackDataHub.stop();
trackController.update(trackId == recordingTrackId, recordingTrackPaused); AnalyticsUtils.dispatch();
} }
@Override @Override
@@ -242,16 +240,13 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
} }
@Override @Override
protected void onStop() { protected int getLayoutResId() {
super.onStop(); return R.layout.track_detail;
trackDataHub.stop();
AnalyticsUtils.dispatch();
} }
@Override @Override
protected void onDestroy() { protected boolean hideTitle() {
super.onDestroy(); return true;
trackRecordingServiceConnection.unbind();
} }
@Override @Override
@@ -422,7 +422,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null); sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
// Update track recording service connection // Update track recording service connection
TrackRecordingServiceConnectionUtils.resumeConnection(this, trackRecordingServiceConnection); TrackRecordingServiceConnectionUtils.startConnection(this, trackRecordingServiceConnection);
trackDataHub.start(); trackDataHub.start();
@@ -145,7 +145,7 @@ public class TrackRecordingServiceConnectionUtils {
* @param trackRecordingServiceConnection the track recording service * @param trackRecordingServiceConnection the track recording service
* connection * connection
*/ */
public static void resumeConnection( public static void startConnection(
Context context, TrackRecordingServiceConnection trackRecordingServiceConnection) { Context context, TrackRecordingServiceConnection trackRecordingServiceConnection) {
trackRecordingServiceConnection.bindIfStarted(); trackRecordingServiceConnection.bindIfStarted();
if (!isRecordingServiceRunning(context)) { if (!isRecordingServiceRunning(context)) {