Kill the process when the debug mode is updated.

Killing the process allows for some settings that are read only on
service start up to be correctly read again.

Change-Id: Ia48f2ca4760a530ac47b727f290d606715cb6bde
This commit is contained in:
Jean Chalard 2011-02-03 17:05:46 +09:00
parent ea55bf5df7
commit f9ec16f9c0

View file

@ -20,6 +20,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Process;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import android.util.Log;
@ -31,6 +32,7 @@ public class DebugSettings extends PreferenceActivity
private static final String DEBUG_MODE_KEY = "debug_mode";
private CheckBoxPreference mDebugMode;
private boolean serviceNeedsRestart = false;
@Override
protected void onCreate(Bundle icicle) {
@ -39,16 +41,24 @@ public class DebugSettings extends PreferenceActivity
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this);
serviceNeedsRestart = false;
mDebugMode = (CheckBoxPreference) findPreference(DEBUG_MODE_KEY);
updateDebugMode();
}
@Override
protected void onStop() {
super.onStop();
if (serviceNeedsRestart) Process.killProcess(Process.myPid());
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals(DEBUG_MODE_KEY)) {
if (mDebugMode != null) {
mDebugMode.setChecked(prefs.getBoolean(DEBUG_MODE_KEY, false));
updateDebugMode();
serviceNeedsRestart = true;
}
}
}