@Override protected void onResume() { super.onResume(); getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); running = getPreferenceScreen().getSharedPreferences().getBoolean(IS_ON, false); runNormal = getPreferenceScreen().getSharedPreferences().getBoolean(ANALYTIC_KEY, false); if (running) { if (runNormal && !AudioRecorderService.isRunning) SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext()); else if (!AudioRecorderServiceLite.isRunning) SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext()); } }
/** Listener for the On/Off switch */ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(ONOFF_KEY)) { running = !running; Editor editor = sharedPreferences.edit(); editor.putBoolean(IS_ON, running); editor.commit(); if (running) { if (runNormal) SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext()); else SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext()); } else { if (runNormal) SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext()); else SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext()); } } if (key.equals(ANALYTIC_KEY)) { runNormal = !runNormal; Editor editor = sharedPreferences.edit(); editor.putBoolean(ANALYTIC_ON, runNormal); editor.commit(); if (running) { if (runNormal) { SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext()); SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext()); } else { SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext()); SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext()); } } } }